管理.htaccess中的多个条件和规则

时间:2018-06-12 18:40:37

标签: .htaccess url-rewriting

我有这些网址:

https://www.example.com/photo-events/photo-exhibition.php?id=1&name=nameexhibit
https://www.example.com/photographers/photographer.php?id=1&name=john-doe

我需要以这种方式改变它:

https://www.example.com/1/nameexhibit
https://www.example.com/1/john-doe

我在.htaccess中添加了这段代码:

#RULE 1
RewriteCond %{THE_REQUEST} /photo-events/photo-exhibition\.php\?id=([^&\s]+)&name=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,NE,L]
RewriteRule ^(\S+)\s+(.*)$ /$1-$2 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^(\S+)$ /$1 [NE,R=302,L]
RewriteRule ^([^/]+)/([^/]+)/?$ /photo-events/photo-exhibition.php?id=$1&name=$2 [L,QSA]

#RULE 2
RewriteCond %{THE_REQUEST} /photographers/photographer\.php\?id=([^&\s]+)&name=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,NE,L]
RewriteRule ^(\S+)\s+(.*)$ /$1-$2 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^(\S+)$ /$1 [NE,R=302,L]
RewriteRule ^([^/]+)/([^/]+)/?$ /photographers/photographer.php?id=$1&name=$2 [L,QSA]

它适用于第一条规则但不适用于第二条规则。在photographer.php页面上没有任何反应,好像服务器忽略了第二条规则。

如何累积重写规则? 任何帮助都会非常感激。

0 个答案:

没有答案