簡體   English   中英

將所有www或非www頁面重定向到https:// www以外的頁面

[英]Redirect all www or non www page to https://www except one page

我正在嘗試執行https://www. 在我所有的頁面上,除了hotels.php 我下面的當前代碼是添加www. 兩次,即https://www.www.example.com

.htaccess

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

RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} \/hotels.php\/
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301]

讓我知道我在這里缺少什么導致問題。 謝謝

嘗試以下重寫條件:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force https:// for all except your desired URLs    
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/hotels.php/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force http:// for your desired URLs
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /hotels.php/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

不是Htaccess regex的高手,這對我有用:

<IfModule mod_rewrite.c>
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
    RewriteRule (.*) https://www.%1/$1 [R=301,L]
</IfModule>

希望能幫助到你! 在StackOverflow上有很多答案……很確定那可能是我得到的!

在檢查HTTPS時,必須檢查www是否在請求URI中。 嘗試這個:

//If has not www and it's not a subdomain adds www
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

//If has not https and it's not hotels.php add https
RewriteCond %{REQUEST_SCHEME} !https
RewriteCond %{REQUEST_URI} !^\/hotels.php\/
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

暫無
暫無

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

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