如何修复.htaccess RewriteRule冲突?

时间:2017-08-21 18:22:01

标签: apache .htaccess mod-rewrite

我有冲突RewriteRule .htaccess。

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
RewriteRule ^unsubscribe.php$/template/site.org/newsletter/unsubscribe.php
RewriteRule ^(unsubscribe)/?$ /$1.php [L,NC]

RewriteRule . /index.php [L]

冲突
RewriteRule ^unsubscribe.php$/template/site.org/newsletter/unsubscribe.php
RewriteRule ^(unsubscribe)/?$ /$1.php [L,NC]

请帮我解决。

1 个答案:

答案 0 :(得分:2)

您的unsubscribe规则需要在模式和目标之间留出空格,但更重要的是,您需要在全部index.php规则之前放置这些规则。您还可以将最后两个规则合并为一个:

RewriteEngine on
RewriteBase /

RewriteRule ^unsubscribe(?:\.php)?$ /template/site.org/newsletter/unsubscribe.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]