【问题标题】:htaccess and friendly urls with more than one parameterhtaccess 和具有多个参数的友好 url
【发布时间】:2016-02-03 18:52:47
【问题描述】:

我没有使用 htaccess 的经验,所以我有这个网址:index.php?id=1163&sub=hp 我已经设法使用 htaccess 将第一部分转换为友好的 url:

www.mytesturl.com/index.php?id=1163 进入 www.mytesturl.com/computers/ 但是我需要转换整个网址(两个参数),例如: www.mytesturl.com/index.php?id=1163&sub=hp 进入 www.mytesturl.com/computers/hp/

这是我的 htaccess:

<IfModule mod_rewrite.c> 
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?perf=$1
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mytesturl.com
RewriteRule (.*) http://www.mytesturl.com/$1 [R=301,L]
</IfModule>  

有人可以指出我正确的方向吗?第二条指令应该在同一行,或者需要添加另一个规则或指令 类似于: RewriteRule (.*) http://www.mytesturl.com/$1 [R=301,L]

【问题讨论】:

    标签: apache .htaccess redirect friendly-url


    【解决方案1】:

    你可以使用:

    RewriteEngine On
    
    RewriteRule ^([\w-]+)/?$ index.php?perf=$1 [L,QSA]
    
    RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?perf=$1&sub=$2 [L,QSA]
    

    但请记住,您的规则使用 ?perf=... 作为第一个参数,而不是您的问题所说的 ?id=...

    【讨论】:

      猜你喜欢
      • 2014-10-04
      • 2011-07-11
      • 1970-01-01
      • 2022-11-29
      • 1970-01-01
      • 2015-12-16
      • 2013-12-15
      • 2012-09-20
      • 2016-01-06
      相关资源
      最近更新 更多