gpt4 book ai didi

apache - Htaccess URL 重定向适用于 http 而不是所有 https

转载 作者:行者123 更新时间:2023-12-04 22:46:59 28 4
gpt4 key购买 nike

htaccess 和重定向方面的新手,我希望有人能帮助我。目前所有 http url 都正确重定向。例如。如果你去 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 url 都将起作用:例如。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 获取任何 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]

关于apache - Htaccess URL 重定向适用于 http 而不是所有 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48205988/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com