簡體   English   中英

.htaccess將http / https www重定向到https non-www

[英].htaccess redirect http/https www to https non-www

我正在瘋狂嘗試與Google Cloud上的wordpress網站進行重定向,例如https:// www https://example.com

我目前正在使用以下內容,在示例中這是最有用的:

RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} !wp-content\/cache\/(all|wpfc-mobile-cache)
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

它指導諸如以下的鏈接: http://www.example.comhttps://example.com

但不會使用https:// www重定向鏈接。

任何幫助將不勝感激。

您可以使用:

RewriteEngine on
# www -> https without www
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
# http -> https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !wp-content/cache/(all|wpfc-mobile-cache)
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

試試看,它應該可以正常工作..這就是將所有“ http”請求重定向到“ https”所需的全部操作,但是請記住,您仍然需要在站點上安裝有效的SSL證書。

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

暫無
暫無

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

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