HTACCESS 重写顺序

发布于 2024-10-21 03:52:21 字数 490 浏览 1 评论 0原文

重写index.php的行和其他三行工作得很好,但放在一起时就不行了,我已经尝试了行位置的所有可能性,说实话,我已经筋疲力尽了。

我的代码如下:

RewriteEngine On
RewriteRule (.*) index.php
RewriteCond %{REQUEST_URI} !^/(admin|admin/.*)$
RewriteCond %{REQUEST_URI} !^/(l|l/.*)$
RewriteCond %{REQUEST_URI} !^/(includes|includes/.*)$

任何人都可以帮我解决这个简单的问题吗?

该脚本运行于: http://domain.com/folder/

.htaccess 也放置在该文件夹中。

问题是它还重写了 admin,l 中的文件并包含文件夹

The line with rewriting index.php and the other three lines work perfectly, but not when put together, I've tried all possibilities with position of the lines, and to be honest pretty exhausted.

My code below:

RewriteEngine On
RewriteRule (.*) index.php
RewriteCond %{REQUEST_URI} !^/(admin|admin/.*)$
RewriteCond %{REQUEST_URI} !^/(l|l/.*)$
RewriteCond %{REQUEST_URI} !^/(includes|includes/.*)$

Can anyone help me in this quick question?

The script runs in: http://domain.com/folder/

The .htaccess is also placed in that folder.

The problem is that it rewrites also files in the admin,l and includes folder

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

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

发布评论

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

评论(2

只为守护你 2024-10-28 03:52:21

我认为这里发生的事情是第一个 RewriteRule (.*) index.php 设置为重写所有内容,无论它们是否与 3 RewriteCond 的其他正则表达式匹配,我认为可能会将其移至底部并重新制定规则以使其更具体满足您的需求。

I think what is happening here is the first RewriteRule (.*) index.php is set to rewrite everything regardless of if they match the other regex for the 3 RewriteCond's I think maybe moving it to the bottom and reformulating the rule to be more specific to your needs.

怎会甘心 2024-10-28 03:52:21

您的 Rewrite 代码中存在很少的问题

  1. RewriteCond 应该出现在 RewriteRule 之前
  2. 多个 RewriteCond 可以合并为 1
  3. 您必须使用 L 标志来标记最后一条规则

将您的代码替换为:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(admin|l|includes)(/.*|)$ [NC]
RewriteRule ^ index.php [L]

There are few problems in your Rewrite code:

  1. RewriteCond should come before RewriteRule
  2. Multiple RewriteCond can be combined into 1
  3. You must use L flag to mark last rule

Replace your code with this:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(admin|l|includes)(/.*|)$ [NC]
RewriteRule ^ index.php [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文