目前,文件扩展名
.php
已从我的 URL 中正确删除。但 www.example.com/thema
下的 URL 不带尾部斜杠,www.example.com/thema/
下的尾部斜杠不带尾部斜杠。
我的
.htaccess
文件内容:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# redirect file.php to /file/
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php\s [NC]
RewriteRule ^ /%1/ [R=302,NE,L]
# added .php extension to /file by checking presence of file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
</IfModule>
您能给我一些建议,需要更改以下几点:
www.example.com
下可用(无尾部斜杠)www.example.com/thema/
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
在此规则中您应该重定向到
https
,而不是 http
。
然后,您可以在此之后添加另一个规则,附加尾部斜杠:
# Append trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.+[^/]$ /$0/ [R=301,L]