.htaccess HTACCESS:Redirect only.php,不带jquery字符串

.htaccess HTACCESS:Redirect only.php,不带jquery字符串,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,当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 R

当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 error

,您可以使用以下命令:

# 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]

这会将all.php重定向到404错误。如果.php有查询字符串,例如:.php?lang=en,我需要避免使用此规则。如果查询字符串存在,则不要对.php文件应用此规则