apache - 如何解决 .htaccess RewriteRule 冲突?

标签 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]

请帮我解决这个问题。

最佳答案

您的取消订阅规则需要在模式和目标之间有一个空格,但更重要的是您需要将这些规则放在catch-all index.php规则之前。您还可以将最后 2 条规则合并为一条:

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]

关于apache - 如何解决 .htaccess RewriteRule 冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45803431/

相关文章:

php - 是否可以知道默认的 PHP include_path 设置在哪里?

php - 服务器无法读取 htaccess 文件,为了安全拒绝访问

apache - 如何编辑.htaccess将子域重定向到端口8080

wordpress - 修改Wordpress中默认生成的友好URL(通过.htaccess)

regex - 如何使用 ProxyMatch 或 ProxyPassMatch 与 Regex 映射多个上下文路径

java - Apache Tomcat server.xml 组件的启动顺序

mysql - Apache - MySQL 服务检测到错误的路径。/端口已在使用中

.htaccess - URL 上的 RedirectMatch 不包含任何参数?

php - 为特定的重写查询添加尾部斜杠

php $SERVER ['PATH_INFO' ] 和 apache mod_rewrite