我希望我的网站将来自www.example.com和example.com或anythingelse.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”
答案 0 :(得分:0)
requinix在devshed
上提供的解决方案RewriteEngine On
RewriteCond %{HTTP_HOST} !this.example.com
RewriteRule ^ http://this.example.com%{REQUEST_URI} [L]