www.example.com 和 example.com 的 .htaccess 重写规则 -> this.example.com
我希望我的网站将所有流量从 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 [email protected]
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”
I would like my site to direct all traffic from www.example.com and example.com or anythingelse.example.com to this.example.com This is what I have in my .htaccess file which is located in /www/example.com/public_html directory
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://this.example.com/ [R=301,L]
It works when I visit this.example.com but when I visit http://example.com it redirects me to example.com/public_html and www.example.com doesn't redirect at all! However this.example.com works. This is my virtual host setting:
<VirtualHost 12.34.56.78:80>
ServerAdmin [email protected]
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>
I've noticed in my error log when I visit: example.com it says "File does not exist: /srv/www/example.com/public_html/public_html"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
requinix 在 开发棚
Solution provided by requinix on devshed