Apache - 添加虚拟目录后无法再使用 mod_rewrite

发布于 2024-12-12 08:12:16 字数 979 浏览 3 评论 0原文

我的 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 技术交流群。

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

发布评论

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

评论(1

伴我心暖 2024-12-19 08:12:17

原帖评论的回答:

好吧,我明白了。我只需要在开始和结束指令中移动重写逻辑。感谢@animuson 的帮助。 – 亨利·弗林克勒

Answer from comment by original poster:

Ok, I figured it out. I just needed to move the rewrite logic within the start and end Directives. Thanks for the help @animuson. – Henry Wrinkler

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文