簡體   English   中英

將HTTP非www重定向到https非www

[英]redirect http non www to https non www

我剛剛切換到HTTPS。 之前,我將重定向設置為非www +無斜杠+無文件擴展名。 我已將重定向更改為HTTPS。 我堅持將http非www重定向到https non-www。 從http www到https非www重定向的效果很好。

我得到的以下代碼主要來自此處的答案。 服務器是Apache 2.4.33(Unix)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]

#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

#Force non-www:
RewriteCond %{HTTP_HOST} ^www\.mysite\.co.uk [NC]
RewriteRule ^(.*)$ https://mysite.co.uk/$1 [L,R=301]

剛剛將網站添加到一個免費的Cloudflare帳戶中,該帳戶會自動將所有http重定向並重寫為https。 救了頭疼,問題解決了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM