我正在尝试将我的.htaccess文件重定向到带有斜杠的任何URL到非尾部斜杠版本。例如。 example.com/contact/到example.com/contact
我需要将http保留为https和www。非中国的。根据我当前的.htaccess文件规则:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*?)/?$ https://%1/$1 [L,R=301,NE]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} !on
RewriteRule ^(.*?)/?$ https://%1/$1 [L,R=301,NE]
答案 0 :(得分:0)
使用以下3条重定向规则替换所有规则:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
## Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [NE,R=301,L]