www.example.com 和 example.com 的 .htaccess 重写规则 -> this.example.com

发布于 2024-11-07 08:51:19 字数 1076 浏览 0 评论 0原文

我希望我的网站将所有流量从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一指流沙 2024-11-14 08:51:19

requinix 在 开发棚

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

Solution provided by requinix on devshed

RewriteEngine On
RewriteCond %{HTTP_HOST} !this.example.com
RewriteRule ^ http://this.example.com%{REQUEST_URI} [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文