mod_rewrite的规则冲突Drving我疯了 [英] Mod_Rewrite Rule Conflict Drving me Crazy
问题描述
我有一个htaccess的如下一些规则冲突的 - 我需要以某种方式使一个条件,使他们不
I have a .htaccess as follows and some rules are conflicting - I need to somehow make a condition so they don't
RewriteEngine On
RewriteRule ^search$ results_template.php [L]
RewriteRule ^load-([a-z0-9-]+)$ index.php?key=$1 [L]
RewriteRule ^([a-z0-9-]+)$ http://domain.com/share/index.php?key=$1 [L]
.htaccess文件位于 http://domain.com/directory/.htaccess
第一条规则是应该只重写名称搜索
到 results_template.php
并停止处理多个规则
The first rule is supposed to just rewrite the name search
to results_template.php
and stop processing more rules
http://domain.com/directory/search
负荷
http://domain.com/directory/results_template.php
第二个规则是应该采取的 ABCDEF-1
从
The second rule is supposed to take the abcdef-1
from
http://domain.com/directory/load-abcdef-1
和它作为一个参数发送到
and send it as a parameter to
http://domain.com/directory/index.php?key=abcdef-1
,然后停止处理规则。
http://domain.com/directory/index.php?key=abcdef-1
and then stop processing rules.
第三个规则是应该采取 ABCDEF-1
从
The third rule is supposed to take the abcdef-1
from
http://domain.com/directory/abcdef-1
和它作为一个参数发送到
and send it as a parameter to
http://domain.com/share/index.php?key=abcdef-1
,然后停止处理规则。
http://domain.com/share/index.php?key=abcdef-1
and then stop processing rules.
我遇到的问题是,无论我如何努力使这些能够良好地合作,每当我要求 HTTP:/ /domain.com/directory/search 第三条规则被调用,我重定向。
The problem I'm having is no matter how I try to make these play nicely together whenever I request http://domain.com/directory/search the third rule is invoked and I'm redirected.
我敢肯定,这只是完整的疲倦或完全愚蠢,但我已经在太多的时间这一小步所以现在任何帮助,真的是一件好事。谢谢
I'm sure it's just complete tiredness or complete stupidity but I've been at this small step for too many hours now so any help would really be good. Thanks
推荐答案
您需要RewriteConds:
You will need RewriteConds:
RewriteEngine On
RewriteBase /directory
RewriteRule ^search$ results_template.php [L]
RewriteRule ^load-([a-z0-9-]+)$ index.php?key=$1 [L]
RewriteCond %{QUERY_STRING} !^results_template.php
RewriteRule ^([a-z0-9-]+)$ http://domain.com/share/index.php?key=$1 [L]
例如。用户请求/检索,那么查询被转换为results_template.php。有了这个新的查询/results_template.php所有的规则都检查了一遍,当然还有最后一个规则适合,因为它是最普遍的。
E.g. a user requests /search, then the query is transformed to results_template.php. With this new query /results_template.php all rules are checked again and of course the last rule fits as it is the most general one.
这篇关于mod_rewrite的规则冲突Drving我疯了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!