多个URL参数重写规则不起作用

时间:2015-04-22 22:09:00

标签: php apache .htaccess mod-rewrite url-rewriting

我正在尝试使URL写入规则正常工作,但在应用规则后它不会显示任何数据。

网址(不重写)

http://example.com/categories.php?explore=design&sc=css

网址(带重写)

http://example.com/design/css/

我有重写规则

#Level-1
RewriteCond %{THE_REQUEST} /categories\.php\?explore=([^\s&]+) [NC]
RewriteRule ^ categories/%1/? [R=302,L,NE]
RewriteRule ^categories/([^/]+)/?$ categories.php?explore=$1 [NC,L,QSA]

#Level-2
RewriteCond %{THE_REQUEST} /categories\.php\?explore=([^\s&]+)&sc=([^\s&]+) [NC]
RewriteRule ^ categories/%1/%2/? [R=302,L,NE]
RewriteRule ^categories/([^/]+)/?$ categories.php?explore=$1&sp=$2 [NC,L,QSA]

以上只适用于1级,第二级错误吗?

1 个答案:

答案 0 :(得分:1)

尝试使用此.htaccess

RewriteCond %{THE_REQUEST} /categories\.php\?explore=([^\s&]+)&sc=([^\s&]+) [NC]
RewriteRule ^ categories/%1/%2/ [R=302,L,NE]
RewriteCond %{THE_REQUEST} /categories\.php\?explore=([^\s&]+) [NC]
RewriteRule ^ categories/%1/ [R=302,L,NE]

RewriteRule ^categories/([^/]+)/([^/]+)/?$ categories.php?explore=$1&sc=$2 [NC,L,QSA]
RewriteRule ^categories/([^/]+)/?$ categories.php?explore=$1 [NC,L,QSA]

(你用第一个sp和最后一个sc写了ActionBarActivity