Andrew Andrew - 2 months ago 11
Apache Configuration Question

.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?

Answer

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

Comments