在 a2hosting 托管了 3 年。今天我注意到,每个表单查询在生成的 URL 末尾都以 %3f 结尾,这会导致 404。这是突然发生的。
这是我的 htaccess 代码,运行了好几年,没有出现任何问题。它删除了 .php 作为扩展名,删除了 ?check= 并将其替换为 /
# To externally redirect /site.com/foo.php?find=123 to site.com/dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\?check=([^&\s]+) [NC]
RewriteRule ^ %1/%2? [R=301,L]
# To internally forward /site.com/foo.php?find=123 to site.com/dir/foo
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?check=$2 [L,QSA]
# Remove .php extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
代码可以改变查询示例
from
https://www.whatever.org/whatever.php?check=msn.com
to
https://www.whatever.org/whatever/msn.com
Right Now i get
https://www.whatever.org/whatever/msn.com%3f
我确实需要删除 %3f
答案1
更新。
玩了一段时间 htaccess 代码后,似乎这个方法可行。更改
# To externally redirect /example.com/foo.php?find=123 to example.com/dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\?check=([^&\s]+) [NC]
RewriteRule ^ %1/%2? [R=301,L]
到
# To externally redirect /dir/foo.php?find=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\?check=([^&\s]+)(?:&(\S+))? [NC]
RewriteRule ^ %1/%2?%3 [R,L]
解决了该问题,查询生成的 URL 后面的 %3f 消失了。