如何更改它,以便在php有查询字符串时不会抛出404错误,例如:test.php?lang=en
# Run Php without filename extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
# Return 404 if original request is .php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]
如果它包含查询字符串,只需删除.php
扩展名而不重定向到404错误
答案 0 :(得分:0)
您可以使用以下内容:
# Run Php without filename extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
# Return 404 if original request is .php and without query_string
RewriteCond %{THE_REQUEST} /.+\.php\s
RewriteRule .* - [L,R=404]