我有一个在1.2.3.4处托管的Wordpress实例,其DNS设置如下:
A foo.com 1.2.3.4
A category.foo.com 1.2.3.4该站点可以从两个主机名访问,但是,我希望请求category.foo.com在foo.com/category上呈现内容。
在工作场景中,以下请求将发挥作用:
category.foo.com -> foo.com/category
category.foo.com/abc -> foo.com/category/abc我目前正试图通过使用mod_rewrite来解决这个问题:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^category.foo.com
RewriteRule ^(.*) /category$ [L]但是,这会导致无限循环,因为每个请求都是重写的。我还尝试使用[NS]标志并使用RewriteRule,认为这将阻止对后续请求的重定向,但情况似乎并非如此。
在mod_rewrite方面,我缺少了什么东西吗?还是应该使用不同的方法呢?
请注意,我不希望category.foo.com重定向到foo.com,因此到达category.foo.com的访问者应该在浏览器中看到这一点。
发布于 2016-04-12 10:13:10
为每个域配置虚拟主机。您可以在主配置文件中配置所有虚拟主机,也可以将每个虚拟主机放在启用站点的目录中的一个单独的文件中。可以找到一些例子,你的这里。可能看起来像这样。
# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>
DocumentRoot "/var/www/wordpress"
ServerName www.example.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/wordpress/category"
ServerName category.example.org
# Other directives here
</VirtualHost>https://serverfault.com/questions/769661
复制相似问题