我是重写规则的新手,我的.htaccess遇到了一个小问题
RewriteEngine On
RewriteRule ^toto\.html$ /toto.php [NC,L]
RewriteCond %{REQUEST_URI} !^/(my|your)/template\.html [NC]
RewriteCond %{REQUEST_URI} !^/(my|your)/example\.html [NC]
RewriteRule ^([^/]*)/([^/]*)/([^\.]*)\.html$ /$1.php?type=$2&name=$3 [NC,L]
RewriteRule ^([^/]*)/([^\.]*)\.html$ /index.php?type=$1&name=$2 [L]
RedirectMatch 404 \.(htaccess|htpasswd|ini|log|sh|inc|bak|bkp|sql|json)$
我在https://htaccess.madewithlove.be/上进行了测试,总是可以正确重写。
当我在虚拟主机上对其进行测试时:
我去http://mydomain.ovh/my/object.html
重写为右:http://mydomain.ovh/index.php?type=my&name=object
但是当我去
重写为错误:在此服务器上找不到请求的URL /redirect:.php。
我不了解这种行为...
所以我测试了新的重写规则,使写/填充操作成为通用脚本:
RewriteEngine On
RewriteRule ^toto\.html$ /toto.php [NC,L]
RewriteCond %{REQUEST_URI} ^/extract/(my|your)/[^\.]+\.html$ [NC]
RewriteRule ^([^/]*)/([^/]*)/([^\.]*)\.html$ /extract.php?type=$2&name=$3 [L]
RewriteCond %{REQUEST_URI} !^/extract.* [NC]
RewriteCond %{REQUEST_URI} !^/(my|your)/template\.html [NC]
RewriteCond %{REQUEST_URI} !^/(my|your)/example\.html [NC]
RewriteRule ^([^/]*)/([^/]*)/([^\.]*)\.html$ /set.php?type=$2&name=$3 [NC,L]
RewriteRule ^([^/]*)/([^\.]*)\.html$ /index.php?type=$1&name=$2 [L]
RedirectMatch 404 \.(htaccess|htpasswd|ini|log|sh|inc|bak|bkp|sql|json)$
我在https://htaccess.madewithlove.be/上进行了测试,总是可以正确重写。
并且当我在虚拟主机上对其进行测试时:
我去http://mydomain.ovh/my/object.html
重写为右:http://mydomain.ovh/index.php?type=my&name=object
我转到http://mydomain.ovh/fill/my/object.html或http://mydomain.ovh/write/your/data.html
重写为右:http://mydomain.ovh/set.php?type=my&name=object或http://mydomain.ovh/set.php?type=your&name=data
但是当我转到http://mydomain.ovh/extract/my/object.html或http://mydomain.ovh/extract/your/data.html时>
重写总是错误
:请求到达脚本,但没有查询字符串...(并且它似乎是重定向?)]["PATH_TRANSLATED"]=> string(19) "redirect:/index.php" ["PATH_INFO"]=> string(30) "/my/object.html" ["SCRIPT_NAME"]=> string(11) "/extract.php" ["REQUEST_URI"]=> string(37) "/extract/my/object.html" ["QUERY_STRING"]=> string(0) "" ["PHP_SELF"]=> string(41) "/extract.php/my/object.html"
有人可以帮忙这些重写规则吗?
我是重写规则的新手,我的.htaccess RewriteEngine在RewriteRule上遇到了一个小问题^ toto \ .html $ /toto.php [NC,L] RewriteCond%{REQUEST_URI}!^ /(my | your) /template\.html [NC] ...
您需要关闭.htaccess顶部的选项MultiViews
,该选项似乎已在Apache配置中为您的网站打开。