【发布时间】:2013-10-26 23:09:00
【问题描述】:
我的 CMS(表达式引擎)需要一些 .htaccess 规则才能重写 URL 中包含 index.php 的请求。我最近注意到这个正则表达式有点太强大了......并且正在搞乱这样的 GET 请求:
domain.com/something/?specialurl=http%3A%2F%2Fsamplesite.com%2Findex.php
这里,index.php 在 GET 参数中,并导致重定向循环。
我需要一个好的策略来允许我的 htaccess 规则继续为我的 CMS 运行,但避免在它们是查询参数的一部分时搞砸事情。我的正则表达式如下...任何想法都值得赞赏...以下是我当前的 .htaccess 规则:
# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
提前致谢
【问题讨论】:
-
我认为没有太多理由对 .htaccess 文件进行 URL 规范化,请参阅下面的答案。
标签: php regex apache .htaccess mod-rewrite