.htaccess Htaccess URL重定向适用于http而不是所有https

0wi1tuuw  于 2022-11-16  发布在  其他
关注(0)|答案(2)|浏览(155)

我是htaccess和重定向的新手,我希望有人能帮我。目前所有的http网址都能正确重定向。例如,如果你去otherdomain.com,它会把你带到maindomian.com。
这目前并不适用于所有https链接。
例如:http -www和非wwwotherdomain.com/blog都将重定向到https://www.mainwebsite.com/blog
这是我所需要的,然而,只要我到了https它做以下:
https-www和非otherdomain.com/blog都将保留在httpsotherdomain.com/blog域上。
这是错误的,因为它需要转到主网站的博客页面。但如果我手动添加了一个页面上的重定向,所有的http和https网址将工作:例如,www和非www http://www.otherdomain.com/newpage将重定向到https://www.mainwebsite.com/welcomehttps://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]

我想知道如何从httpswww.example.com获得任何网址otherdomain.com,以转到mainwebsite.com?。任何帮助都将不胜感激。

fruv7luv

fruv7luv1#

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 ^blog/?$ http://www.newsite.com/blog [L,R=301,NC]
brccelvz

brccelvz2#

建议使用:重定向301的HTTP到HTTPS(主人是)在我的情况下,我这是最好的
对我来说这是最好的
重写引擎打开重写条件%{HTTPS}关闭重写规则^(.)$https:// %{HTTP_HOST}%{请求URI} [L,R=301]重写条件%{HTTP_HOST} ^www.(.+)$ [NC]重写规则^https://%1% {请求URI} [R=301,L]重写条件%{HTTP_HOST} ^108.161.161.46重写规则(.)https://ayuda.ml/ $1 [R=301,L]重写基础/重写条件%{请求文件名}!-f重写条件%{请求文件名}!-d重写规则^(.)$404.php?%{查询字符串} [NE,L]重写规则. - [E

相关问题