【问题标题】:.htaccess rewrite rules for www.example.com and example.com -> this.example.com.htaccess 重写 www.example.com 和 example.com -> this.example.com 的规则
【发布时间】:2011-08-25 10:51:12
【问题描述】:

我希望我的网站将所有流量从 www.example.com 和 example.com 或任何其他.example.com 引导到 this.example.com 这就是我的 .htaccess 中的内容位于 /www/example.com/public_html 目录中的文件

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://this.example.com/ [R=301,L]

当我访问 this.example.com 时它可以工作,但是当我访问 http://example.com 时它会将我重定向到 example.com/public_html 而 www.example.com 根本不会重定向!但是 this.example.com 有效。这是我的虚拟主机设置:

<VirtualHost 12.34.56.78:80>
 ServerAdmin webmaster@example.com
 ServerName example.com
 ServerAlias this.example.com
 ServerAlias www.example.com
 DocumentRoot /srv/www/example.com/public_html/
 ErrorLog /srv/www/example.com/logs/error.log
 CustomLog /srv/www/example.com/logs/access.log combined
</VirtualHost>

当我访问 example.com 时,我注意到我的错误日志中显示“文件不存在:/srv/www/example.com/public_html/public_html”

【问题讨论】:

    标签: apache .htaccess mod-rewrite apache2


    【解决方案1】:

    requinix 在devshed提供的解决方案

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !this.example.com
    RewriteRule ^ http://this.example.com%{REQUEST_URI} [L]
    

    【讨论】:

      猜你喜欢
      • 2014-03-04
      • 1970-01-01
      • 2015-11-18
      • 2017-07-04
      • 2014-11-11
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      • 2016-04-29
      相关资源
      最近更新 更多