[英]Htaccess URLs redirects are working for http not all https
htaccess和重定向的新手,希望有人可以幫助我。 目前,所有的http網址都已正確重定向。 例如,如果您轉到otherdomain.com,它將帶您前往maindomian.com。
當前不適用於所有https鏈接。
例如:http-www和非www otherdomain.com/blog都將重定向到https://www.mainwebsite.com/blog
這就是我需要的,但是,一旦我進入https,它就會執行以下操作:
https-www和非www otherdomain.com/blog都將保留在https otherdomain.com/blog域中。
這是錯誤的,因為它需要轉到主網站的博客頁面。 但是,如果我在頁面上手動添加了重定向,則所有的http和https網址都可以使用:例如www和非www http://www.otherdomain.com/newpage都將重定向到https://www.mainwebsite.com/歡迎 https://www.otherdomain.com/newpage將重定向到https://www.mainwebsite.com/welcome
這是Drupal 7,這是我目前擁有的代碼:
Redirect /newpage https://www.mainwebsite.com/welcome RewriteEngine on RewriteBase / # Force HTTPS RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] # Remove trailing slash RewriteRule ^(.*)/$ https://%{HTTP_HOST}/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^mainwebsite.com$ [NC] RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Set "protossl" to "s" if we were accessed via https://. This is used later # if you enable "www." stripping or enforcement, in order to ensure that # you don't bounce between http and https. RewriteRule ^ - [E=protossl] RewriteCond %{HTTPS} on RewriteRule ^ - [E=protossl:s] # Make sure Authorization HTTP header is available to PHP # even when running as CGI or FastCGI. RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # Pass all requests not referring directly to files in the filesystem to # index.php. Clean URLs are handled in drupal_environment_initialize(). RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^ index.php [L]
知道如何從https otherdomain.com獲取任何URL轉到mainwebsite.com嗎? 任何幫助將不勝感激。
RewriteEngine on
RewriteCond %{HTTP_HOST} ^othersite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.othersite.com [NC]
RewriteRule ^(.*)$ https://www.mainwebsite.com/$1 [L,R=301,NC]
這將重定向所有請求,而不僅僅是/ blog
如果您只想/ blog重定向,那么我會稍微調整RewriteRule
RewriteRule ^blog/?$ http://www.newsite.com/blog [L,R=301,NC]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.