我正在.htaccess文件中使用以下代码来删除PHP扩展名:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
当我请求例如https://example.com/testfile
时,它可以正常工作。但是,当我请求https://example.com/testfile.php
时,它将重定向到http://example.com:443/testfile
,这将返回Bad Request
响应(HTTP上的端口443)。在我的本地测试服务器上,它可以正常工作并正确重定向。但是在我的远程服务器上发生了。是什么原因造成的?
两个Apache版本均为2.4.39
请注意,我无权访问远程服务器上的服务器配置文件。