Sunday, May 26, 2019

.htaccess - Remove "www." from url with forceful https





I am using the following in my .htaccess file to force https on any user that is visiting my website without https in the url.



However, if the user visits https://www.mysite.co, I want to be able to remove the www from the request.



Please can you tell me what I need to modify in my .htaccess file in order to remove the www from the url while maintaining the forceful https?




Thanks,



Max.



RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]

Answer




Do it with 2 rewrites.



RewriteEngine On 

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...