![](/img/trans.png)
[英].htaccess force redirect of https://www to https:// not working
[英]htaccess: Redirect to https not working with out www
我剛剛借助此鏈接在CentOS 7.3中安裝了Origin CA證書,然后使用以下.htaccess
命令將所有http
請求重定向到https
和www
重定向到non-www
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
這是以下問題,
1)當我RewriteCond %{HTTPS} off
它給出了Too Many Redirects
錯誤
2)當我使用以下URL http://website.com訪問該網站時,它不會重定向到https
3),但是http://www.website.com可以正常工作(使用WWW)
不知道我在SSL配置中做錯了什么,任何幫助將不勝感激。
您可以使用以下單個規則替換http->https
和www->non-www
重定向規則:
RewriteEngine On
# remove www and turn on https rule
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTP:X-Forwarded-SSL} =off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.