【发布时间】:2016-11-21 16:15:54
【问题描述】:
我已将我的网站更改为 ssl。它工作正常,网站内部的所有链接都可以工作,但指向 http 版本的外部链接已损坏,因为域名末尾的斜杠丢失了,例如
astarmathsandphysics dot com/a-level-physics-notes/thermal-physics-and-gases/a-level-physics-notes-prevosts-theory-of-heat-exchange.html
.com 重定向后缺少斜杠
我需要强制使用斜杠。在 apache2 配置文件中,我已重定向到带有斜杠的 ssl 版本,并将此代码插入到我的 .htaccess 文件中
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1/ [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
同样从非 ssl www 重定向到 ssl 非 www 会在 .com 之后插入一个额外的斜杠
【问题讨论】:
标签: apache .htaccess redirect mod-rewrite ssl