Home Correctly write redirect in htaccess to force https and www version of a url
Reply: 0

Correctly write redirect in htaccess to force https and www version of a url

Patrick Sharer
1#
Patrick Sharer Published in 2018-02-08 18:38:56Z

This is how I am attempting to force www and HTTPS urls in htaccess right now.

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

The problem is that this still creates a redirect loop. It first redirects to https://example.com and then redirects to https://www.example.com

Is there a way to correctly write this in htaccess so that it redirects to both https and www at the same time eliminating the redirect loop?

I have tried many examples that I have found here on stackoverflow and they all render redirect loops. Is this unavoidable?

Thanks!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.340457 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO