【问题标题】:remove www from URL从 URL 中删除 www
【发布时间】:2018-09-18 17:41:17
【问题描述】:

我的网站已托管在https://example.com

但问题是当我尝试使用https://www.example.com 访问它时,它仍然可以访问。但我不想让用户使用 www 而不是它来访问该站点,我想将其重定向到 https://example.com 。如何实现?

这是当前的 .htaccess

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

【问题讨论】:

标签: apache .htaccess


【解决方案1】:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

【讨论】:

    猜你喜欢
    • 2014-12-09
    • 1970-01-01
    • 2016-10-01
    • 2013-12-02
    • 1970-01-01
    • 2017-03-31
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多