HTACCESS:仅重定向.php而不使用jquery字符串

时间:2018-06-03 20:49:16

标签: .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
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]

如果它包含查询字符串,只需删除.php扩展名而不重定向到404错误

1 个答案:

答案 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]