子文件夹和 mod-rewrite

发布于 2024-07-24 23:57:20 字数 849 浏览 13 评论 0原文

我需要更改当前的重写规则以适应管理文件夹。 这是我当前的 mod 重写代码:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+?)/([a-z]+?)/(.*)$ index.php?model=$1&view=$2¶ms=$3 [L,NS]

我有这样的文件夹结构:

ROOT:  http://www.domain.com/
ADMIN: http://www.domain.com/admin/

如果 .htaccess 文件位于“admin”文件夹中,则它可以正常工作。 我得到:

URL: http://domain.com/admin/faq/edit/13/asc
(NOTE: http://domain.com/admin/.htaccess)
Array
(
    [model] => faq
    [view] => edit
    [params] => 13/asc
)

但是,当它位于根文件夹中时,我得到:

URL: http://domain.com/admin/faq/edit/13/asc
(NOTE: http://domain.com/.htaccess)
Array
(
    [model] => admin
    [view] => faq
    [params] => edit/13/asc
)

我希望 mod-rewrite 能够识别该 admin 文件夹,并且是一个实际目录并使用单独的重写规则。

提前致谢。

I need to alter this current re-write rule to accommodate for an admin folder. Here is my current mod-rewrite code:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+?)/([a-z]+?)/(.*)$ index.php?model=$1&view=$2¶ms=$3 [L,NS]

I have this folder structure:

ROOT:  http://www.domain.com/
ADMIN: http://www.domain.com/admin/

If the .htaccess file is in the "admin" folder it works correctly. I get:

URL: http://domain.com/admin/faq/edit/13/asc
(NOTE: http://domain.com/admin/.htaccess)
Array
(
    [model] => faq
    [view] => edit
    [params] => 13/asc
)

But, when its in the root folder I get:

URL: http://domain.com/admin/faq/edit/13/asc
(NOTE: http://domain.com/.htaccess)
Array
(
    [model] => admin
    [view] => faq
    [params] => edit/13/asc
)

I want the mod-rewrite to recognize that admin folder and is an actual directory and use a separate re-write rule.

Thanks in advance.

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

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

发布评论

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

评论(2

眸中客 2024-07-31 23:57:20

添加

RewriteCond ^admin/
RewriteRule (your Rule) [L]

在其他条件之前。 这应该够了吧。

另一种方法是直接通过以下方式将条件包含在规则中

RewriteRule ^admin/(rest_of_regex)$ (regex_stuff) [L]

Add

RewriteCond ^admin/
RewriteRule (your Rule) [L]

before the other condition. That should do the trick.

Another way would be to include the condition in the rule directly via

RewriteRule ^admin/(rest_of_regex)$ (regex_stuff) [L]
红焚 2024-07-31 23:57:20

将其添加到您的根 .htaccess:

RewriteCond ^admin/
RewriteRule (whatever rule you need for the admin folder) [L]

将其添加到 RewriteEngine On 之后。 这里的关键点是 [L] ,它告诉 mod-rewrite 如果这条规则匹配,则停止执行其余规则。 如果 admin 文件夹需要多个规则,只需添加更多 RewriteRule 语句,但请记住仅将 [L] 添加到最后一个。

应该可以做到这一点。

Add this to your root .htaccess:

RewriteCond ^admin/
RewriteRule (whatever rule you need for the admin folder) [L]

Add this right after the RewriteEngine On. The key point here is [L] which tells mod-rewrite to stop executing the rest of the rules if this one matches. If you need more than one rule for the admin folder, just add more RewriteRule statements, but remember to only add the [L] to the last one.

That should do it.

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