Siva
Siva

Reputation: 3327

redirect www and non-www to https www .htaccess not working

Please don't say, its duplicate I have been through all threads but none of them worked for me.

I have installed SSL and want to redirect www and non-www to https://www

I have this code .htaccess

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^ven7\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.ven7.com/$1 [R,L]

This is working fine, redirecting domain.com to https://www.ven7.com But if I hit www.ven7.com, page is loading fine but its taking http, so I have changed script to..

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^ven7\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.ven7\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.ven7.com/$1 [R,L]

With this code redirection is working but page is not loading, giving some error, too many re-directions.

How can i fix this? and want this redirection permanently.

Thanks

Upvotes: 0

Views: 967

Answers (1)

Croises
Croises

Reputation: 18671

You can use:

RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
RewriteCond %{HTTPS} off 
RewriteRule ^ https://www.ven7.com%{REQUEST_URI} [NE,R=301,L]

If you need to test the domain name, add first line:

RewriteCond %{HTTP_HOST} (?:^|\.)ven7\.com$ [NC]

And use:

RewriteEngine On
RewriteCond %{HTTP_HOST} (?:^|\.)ven7\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^ https://www.ven7.com%{REQUEST_URI} [NE,R=301,L]

Upvotes: 2

Related Questions