Daniel Williams
Daniel Williams

Reputation: 2317

Forcing non-secure page to redirect to secure page with htaccess

Sorry I don't have code, but I didn't see the point in pasting something that's not even right.

I want to use htaccess so that the following url combos redirect:

http:// www.mysite.com 
http:// mysite.com
https:// www.mysite.com

All should redirect user to

https:// mysite.com

Appreciate guidance.

Upvotes: 0

Views: 63

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

To force https and non-www, you can use this :

RewriteEngine on


RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]

Upvotes: 1

Related Questions