Remove “www.” from url with forceful https [closed]

ⅰ亾dé卋堺 提交于 2019-12-26 06:27:31

问题


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]

回答1:


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]


来源:https://stackoverflow.com/questions/13317691/remove-www-from-url-with-forceful-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!