【问题标题】:.htaccess - Redirect www and non www of my domain to subdomain.htaccess - 将我的域的 www 和非 www 重定向到子域
【发布时间】:2013-09-18 11:45:35
【问题描述】:

我有一个域名 www.example.com。此外,我在目录 blog 下的该域中安装了一个博客。 www.example.com/blog 是我网站的博客 URL。

我需要通过 htacess 文件将 www.example.com 和 example.com 重定向到 www.example.com/blog。目前我的 htaccess 确实将 www.example.com 重定向到 www.example.com/blog。但它将非 www URL example.com 重定向到 www.example.com/blog

我不确定如何解决这个问题。这是我的 htaccess 代码。

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule ^(/)?$ blog [L]
ErrorDocument 404 http://www.example.com/blog/

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite


    【解决方案1】:

    用这个替换你的代码:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
    RewriteRule ^/?$ blog [L]
    
    ErrorDocument 404 /blog/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-27
      • 2015-05-19
      • 1970-01-01
      • 2014-03-25
      相关资源
      最近更新 更多