Dani
Dani

Reputation: 15079

htaccess redirects to http instead of https

I've set a redirect rule in htaccess - but instead of redirecting the url to the right scheme (https) it first redirect to http. for example:

RewriteRule ^prefixurl/(aaa|bbb|ccc)/suffixurl$ prefixurl/ddd/suffixurl [R=301,QSA,L]

What happens is I get from :

https://www.example.com/prefixurl/bbb/suffixurl

--> (redirects to)

http://www.example.com/prefixurl/ddd/suffixurl

--> (2nd redirect to)

https://www.example.com/prefixurl/ddd/suffixurl

(there is nginx server in front of Apache with directive to move all non https back to https...)

Why the redirect to http takes place ? any way to fix it ?

Upvotes: 1

Views: 126

Answers (1)

anubhava
anubhava

Reputation: 785971

You may use this single rule to get your redirect and get https:// in redirected URL:

RewriteRule ^prefixurl/(aaa|bbb|ccc)/suffixurl$ https://%{HTTP_HOST}/prefixurl/ddd/suffixurl [R=301,NC,L]

Upvotes: 1

Related Questions