简体   繁体   English

.htaccess重写条件以将链接从http重定向到https

[英].htaccess rewrite condition to redirect links from http to https

I have a lot of different links without any logical rules, that are redirected with .htaccess Redirect 301 我有很多没有任何逻辑规则的不同链接,这些链接都通过.htaccess Redirect 301

.htaccess looks like this: .htaccess看起来像这样:

<IfModule mod_rewrite.c>

    RewriteCond %{HTTP_HOST} ^mysyte.com

    Redirect 301 /oldlink1 /newlink1
    Redirect 301 /oldlink1 /newlink1
    Redirect 301 /oldlink1 /newlink1

    ...

Some days ago I've set up https. 几天前,我已经设置了https。 Unfortunately, https://mysyte.com/oldlink... redirects to http://mysyte.com/newlink... - not to https but http. 不幸的是, https://mysyte.com/oldlink...重定向到http://mysyte.com/newlink...不是https而是http。

What i'm doing wrong? 我做错了什么? How should I set up .htaccess file to redirect to https? 我应该如何设置.htaccess文件以重定向到https?

If you're changing protocols or sites, then you HAVE to use an absolute url: 如果要更改协议或站点,则必须使用绝对URL:

Redirect 301 /oldlink https://example.com/newlink1
                      ^^^^^^^^^^^^^^^^^^^

otherwise it's just a "local" redirect and you stay within the same site/protocol. 否则,它只是一个“本地”重定向,并且您位于同一站点/协议中。

And note that Redirect is NOT part of mod_rewrite. 并请注意, Redirect不是mod_rewrite的一部分。 That's a core directive in Apache (part of mod_alias) and has nothing to do with mod_rewrite at all: http://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect 这是Apache(mod_alias的一部分)中的核心指令,与mod_rewrite完全无关: http : //httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM