这目前不适用于所有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/welcome 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获取任何网址到mainwebsite.com?任何帮助将不胜感激。
答案 0 :(得分:0)
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]