在虚拟主机中应用mod_rewrite

发布于 2024-09-12 07:09:40 字数 316 浏览 2 评论 0原文

我想重写虚拟主机中的网址。

虚拟目录:

htdoc/dev/ , dev.com

htdoc/dev 中的 .htaccess 中的语法:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule test.html$ test.php [L]
</IfModule>

我能够在本地主机中将 test.html 重写为 test.php。但是,无法在虚拟主机中执行此操作。这里出了什么问题?

I would like to rewrite url in virtual host.

Virtual directory:

htdoc/dev/ , dev.com

Syntax in .htaccess in htdoc/dev:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule test.html$ test.php [L]
</IfModule>

I am able to rewrite test.html to test.php in localhost. However, not able to do it in virtual host. What went wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

谜泪 2024-09-19 07:09:40

请检查您是否将 AllowOverride 选项设置为 All

<VirtualHost...>
    ...
    AllowOverride All
    ...
</VirtualHost>

Please check that you have AllowOverride option set to All:

<VirtualHost...>
    ...
    AllowOverride All
    ...
</VirtualHost>
ˉ厌 2024-09-19 07:09:40

需要在 httpd.conf 的目录部分中完成...

<Directory "/var/www/html">
    AllowOverride All
</Directory>

...如果使用虚拟主机,您需要添加虚拟主机目录,如下所示...

<Directory "/var/www/html/virtual_host_directory">
    AllowOverride All
</Directory>

Needs to be done in httpd.conf in the directory section...

<Directory "/var/www/html">
    AllowOverride All
</Directory>

...if using Virtual Hosting, you'd need to add the virtual host directory as in...

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