Mobile app version of vmapp.org
Login or Join
Pierce454

: Non-www along with https I need to set the following rules: redirect www to non-www (close www) redirect http to https (close http) Suppose I have example.com , How to set the above rules

@Pierce454

Posted in: #Htaccess #Https #NoWww

I need to set the following rules:


redirect www to non-www (close www)
redirect http to https (close http)


Suppose I have example.com , How to set the above rules together in htaccess?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Pierce454

2 Comments

Sorted by latest first Latest Oldest Best

 

@Smith883

Here is the shorter version of your code :

RewriteEngine on


RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^ www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]

10% popularity Vote Up Vote Down


 

@Gretchen104

I solved this problem via :

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


RewriteCond %{SERVER_PORT} 80 [NC]
RewriteRule ^(.*)$ example.com/ [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme