【问题标题】:Remove "www." from url with forceful https [closed]删除“www”。来自具有强大 https 的 url [关闭]
【发布时间】:2012-10-30 08:10:32
【问题描述】:

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

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

请你告诉我我需要在我的 .htaccess 文件中修改什么,以便在保持强大的 https 的同时从 url 中删除 www 吗?

谢谢,

最大。

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

【问题讨论】:

标签: .htaccess mod-rewrite https


【解决方案1】:

进行 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]

【讨论】:

  • 来自 Zak 和 aam1r 的链接中的优秀 cmets。
  • 当我使用www.mysite.co 时有效,但当我使用https://www.mysite.co 时无效
  • 我的错误 - 匹配查询字符串而不是 http_host。
  • 完美运行,谢谢!
猜你喜欢
  • 2015-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-31
  • 2014-03-23
  • 2021-06-05
相关资源
最近更新 更多