简体   繁体   中英

.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 looks like this:

<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. Unfortunately, https://mysyte.com/oldlink... redirects to http://mysyte.com/newlink... - not to https but http.

What i'm doing wrong? How should I set up .htaccess file to redirect to https?

If you're changing protocols or sites, then you HAVE to use an absolute 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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