删除“www。”从强大的https网址(Remove "www." from url with forceful https)

其他开发 IT屋
百度翻译此文   有道翻译此文
问 题

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]
解决方案

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]

本文地址:IT屋 » Remove "www." from url with forceful https

问 题

我在我的.htaccess文件中使用以下内容强制https访问我的网站没有https的任何用户。



但是,如果用户访问 https://www.mysite.co ,我希望能够从请求中删除www。



请告诉我在.htaccess文件中需要修改的内容,以便在保持强制https的同时从网址中删除www?



谢谢,



最多。



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

解决方案

用2次重写做。



  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]

本文地址:IT屋 » 删除“www。”从强大的https网址

官方微信
扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注
与百万开发者在一起