.HTACCESS子域重定向

时间:2017-09-18 07:58:54

标签: php apache .htaccess redirect mod-rewrite

我遇到子域名问题..我有一个子域名content.domain.com 我想用于无cookie域名内容..

但当我在网站上写它..它自动添加完整的网站网址..我已经添加了.htaccess

您能告诉我如何停止重定向子域名....

请帮忙......

这里是域重写的htaccess代码

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

1 个答案:

答案 0 :(得分:1)

  1. 您可以将两个规则合并为一个规则
  2. 使用RewriteCond可以省略子域名。
  3. 有这样的话:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
    RewriteCond %{HTTPS} !on
    RewriteCond %{HTTP_HOST} ^(?!content\.domain\.com)(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
    

    确保在测试此更改时清除浏览器缓存。

相关问题