子文件夹和mod-rewrite [英] Subfolders and mod-rewrite

查看:130
本文介绍了子文件夹和mod-rewrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要改变这种电流重写规则,以适应一个管理员文件夹。这是我目前的mod-rewritecode:

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/

如果.htaccess文件是在管理文件夹,它工作正常。我得到:

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
)

我想mod-rewrite认识到管理文件夹,是一个实际的目录,并使用单独的重写规则。

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

先谢谢了。

推荐答案

添加到您的.htaccess根:

Add this to your root .htaccess:

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

添加 RewriteEngine叙述后,这一权利在。这里的关键点是 [L] 告诉mod-rewrite停止执行的其余规则,如果这一块匹配。如果您需要的管理文件夹多个规则,只需添加更多的重写规则的语句,但记住只添加 [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.

这应该这样做。

这篇关于子文件夹和mod-rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆