Apache - 添加虚拟目录后无法再使用 mod_rewrite
我的 apache 服务器是用非常基本的配置设置的。我曾经只从 apache 提供一个网站,我们称之为 example.com。在 httpd.conf 文件中,我有一些代码强制网站始终在 url 中显示 www。
我最近为该网站添加了一个子域 blog.example.com。为此,我需要在 httpd.conf 文件中创建 2 个虚拟目录指令。
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /var/www/blog
</VirtualHost>
在此之后,我立即保留了重写代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R]
问题是,在添加虚拟目录代码后,重写代码不再起作用。我尝试创建以下目录指令,但它似乎根本不起作用。
<Directory "/var/www/html">
Options Indexes MultiViews FollowSymLinks
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
此外,我尝试在网站的 html 文件夹中创建一个 .htaccess 文件并重新启动 apache,但我放入其中的任何内容都没有被注意到。
非常感谢任何帮助。谢谢!
My apache server is set up with a very basic configuration. I used to serve just one website from apache, let's call it example.com. Within the httpd.conf file, I had some code to force the website to always show www in the url.
I recently added a subdomain for the site, blog.example.com. In order to do this I needed to create 2 virtual directory directives within my httpd.conf file.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /var/www/blog
</VirtualHost>
Immediately after this, I kept my rewrite code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R]
The problem is that this after adding the Virtual Directory code, the rewrite code is no longer working. I tried creating the following Directory directive, which doesn't seem to work at all.
<Directory "/var/www/html">
Options Indexes MultiViews FollowSymLinks
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
Additionally, I tried creating a .htaccess file in the html folder of the website and restarting apache, but nothing that I put in there is getting noticed at all.
Any help is greatly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原帖评论的回答:
Answer from comment by original poster: