子文件夹和 mod-rewrite
我需要更改当前的重写规则以适应管理文件夹。 这是我当前的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加
在其他条件之前。 这应该够了吧。
另一种方法是直接通过以下方式将条件包含在规则中
Add
before the other condition. That should do the trick.
Another way would be to include the condition in the rule directly via
将其添加到您的根 .htaccess:
将其添加到
RewriteEngine On
之后。 这里的关键点是[L]
,它告诉 mod-rewrite 如果这条规则匹配,则停止执行其余规则。 如果 admin 文件夹需要多个规则,只需添加更多 RewriteRule 语句,但请记住仅将[L]
添加到最后一个。应该可以做到这一点。
Add this to your root .htaccess:
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.