所以我有两个规则。每个规则在.htaccess
本身时就完全应该做到了,但是当两个规则都存在时,它们就开始相互冲突。
RewriteCond %{REQUEST_URI} ^(.*)\.html$
RewriteRule ^(.*)\.html$ index.php?id=$1 [QSA,L]
如果数字以http://domain.com/12.html
结束,上述规则适用于说12
并将数字index.php
传递到.html
( note 12.html
文件不存在!)
RewriteCond %{REQUEST_URI} !^(.*)\.html$
RewriteRule ^(.*)$ /$1\.html [L,R=301]
这适用于检查网址是否以.html
结尾。如果它没有以.html
结束,它会将其重定向到URI + .html
(这也可以正常工作)。
当我在.htaccess
RewriteCond %{REQUEST_URI} ^(.*)\.html$
RewriteRule ^(.*)\.html$ index.php?id=$1 [QSA,L]
RewriteCond %{REQUEST_URI} !^(.*)\.html$
RewriteRule ^(.*)$ /$1\.html [L,R=301]
然后有一个循环导致重定向循环。
有人可以指出我哪里出错吗?
答案 0 :(得分:1)
因此,第一条规则将http://domain.com/12.html
重写为http://domain.com/index.php?id=12
。事情开始变得糟糕;第二条规则将其重写为http://domain.com/index.php.html?id=12
,但此时我认为您会发现第一条规则再次启动,将其重写为类似http://domain.com/index.php?id=index.php
的内容,第二条规则重写为{{1} }}。在这一点上,我认为规则最终会争夺URL。
最简单的解决方案可能是调整第二次重写规则,不要重写已包含扩展名的网页,即使用http://domain.com/index.php.html?id=index.php
代替[^.]*
。