我的htaccess文件包含
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]+\s([^\s]+)\.php\s
RewriteRule .* %1.html [R=301,L]
RewriteRule ^(.*)\.html$ $1.php
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^.*$ - [L]
RewriteRule ^index.php$ http://%{http_host}/ver1 [R=301,L]
并且工作正常
但我的表单操作需要指向.php文件
如何防止form.php被重写?
我不希望将form.php文件重写为form.html
答案 0 :(得分:0)
在第一行
后立即尝试此代码RewriteCond %{REQUEST_URI} !^(.*)form.php(.*)$
此代码检查请求字符串中是否有“form.php”,如果是 - 仅中止 RewriteRule。
编辑: 好吧,我的错,我一个接一个地重复了2个重写规则。我将您的代码格式化为更好的形式和描述..请试试这个:
RewriteEngine on
# 1st rule
RewriteCond %{REQUEST_URI} !^(.*)form.php(.*)$
RewriteCond %{THE_REQUEST} ^[A-Z]+\s([^\s]+)\.php\s
RewriteRule .* %1.html [R=301,L]
# 2nd rule
RewriteCond %{REQUEST_URI} !^(.*)form.html(.*)$
RewriteRule ^(.*)\.html$ $1.php
# 3rd rule
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^.*$ - [L]
# 4th rule
RewriteRule ^index.php$ http://%{http_host}/ver1 [R=301,L]