删除www。从子域通过.htaccess?

时间:2016-04-27 10:26:28

标签: .htaccess redirect mod-rewrite

我目前有以下内容:

  1. 删除www。从网址和重定向到https://somedomain.com
  2. 将http://请求重定向到https://
  3. 这很好用,这是代码......

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
    
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
    

    我现在面临的问题是..如何删除www。来自子域 例如https://www.subdomain.maindomain.com并将其重定向到 https://subdomain.maindomain.com

    希望有人可以惹恼

2 个答案:

答案 0 :(得分:0)

尝试:

RewriteEngine on


RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]

答案 1 :(得分:0)

要从子域中删除WWW,请使用以下命令:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]