在不使用 .htaccess 文件的情况下,我应该将 RewriteRules 放在 Apache2 中的哪里?

发布于 2024-09-24 16:25:52 字数 517 浏览 1 评论 0原文

我想在不使用 .htaccess 文件的情况下配置 mod_rewrite 规则。当我将规则放入 .htaccess 文件中时,它们可以正常工作,但我更愿意将所有配置保留在 /etc/apache2/sites-available/[site name] 配置文件中。

当我将相同的 RewriteRules 放入 VirtualHost 或 Directory 指令中时,没有任何效果。我做错了什么?这是我的 VirtualHost 配置文件中的一个示例:

<Directory />
 Options FollowSymLinks
 # AllowOverride is on for the .htaccess files to work
 AllowOverride All
 RewriteEngine On
 RewriteRule ^oldsite\.php$ newsite.php
</Directory>

我想我可能忽略了 apache2.conf 文件中的某些指令,但我不确定。帮助。 :)

I want to configure a mod_rewrite rule without using .htaccess files. When I put rules in .htaccess files they work fine, but I would prefer to leave all of the configuration in my /etc/apache2/sites-available/[site name] config file.

When I place the same RewriteRules within the VirtualHost or Directory directives, nothing works. What am I doing wrong? Here is a sample from my VirtualHost config file:

<Directory />
 Options FollowSymLinks
 # AllowOverride is on for the .htaccess files to work
 AllowOverride All
 RewriteEngine On
 RewriteRule ^oldsite\.php$ newsite.php
</Directory>

I'm thinking I might be overlooking some directive within the apache2.conf file, but I'm not sure. Help. :)

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

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

发布评论

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

评论(1

胡渣熟男 2024-10-01 16:25:52

您正在使用 RewriteRule 模式,这意味着对于 .htaccess 文件。原因:

在 .htaccess 文件中使用重写引擎时,每个目录的前缀(对于特定目录始终相同)会自动删除以进行模式匹配,并自动添加 em> 替换完成后。

因此,请使用完整的 URL 路径尝试此规则:

RewriteRule ^/oldsite\.php$ /newsite.php

You’re using a RewriteRule pattern that is meant for an .htaccess file. The reason:

When using the rewrite engine in .htaccess files the per-directory prefix (which always is the same for a specific directory) is automatically removed for the pattern matching and automatically added after the substitution has been done.

So try this rule with the full URL path:

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