我正在尝试在无法访问mod_rewrite
的Apache服务器上使用httpd.conf
,因此我使用此.htaccess
文件:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{2,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.php
它应该将http:
重定向到https:
并附加" .php"如果没有文件扩展名。例如:
http://my.web.server.de/helloworld/m/contact ––>
https://my.web.server.de/helloworld/m/contact.php
https:
重定向有效,但是当我省略" .php"文件扩展名,我收到404错误。没有错误写入日志。
我认为可能是SSL问题,所以我删除了HTTPS部分:
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{2,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.php
但它仍然无法正常工作,文件结尾不会被附加。我被灌输了。为什么它不起作用?
服务器是Apache / 2.4.18(Ubuntu)。