If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the .htaccess files), try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
发布评论
评论(2)
这条规则
将匹配以
/
结尾的字符串,后跟字母数字字符串,因此它将匹配gallery/hgJ56
,因为它以/hgJF6
结尾。如果规则仅匹配以
/
开头,后跟字母数字字符串的字符串,那么您可以将此规则更改为,它将不再匹配
gallery/hgJ56
并且您的其他规则将起作用。请注意,您不需要转义
/
字符,即\/
和/
是等效的。您可能还想将
^
应用于其余规则,以防它们也只应该匹配字符串的开头,即更改为
This rule
will match a string that ends with a
/
followed by an alphanumeric string, so it will matchgallery/hgJ56
, because it ends with/hgJF6
.If the rule is only supposed to match a string that begins with a
/
followed by an alphanumeric string, then you can change this rule toand it will not longer match
gallery/hgJ56
and your other rule will work.Note that you do not need to escape the
/
character i.e.\/
and just/
are equivalent.You may also want to apply the
^
to the rest of your rules in case they also are only supposed to match the start of the string i.e changeto
这是您的重写规则的“更干净”版本。
告诉我它们是否有效。
如果这还不够:
两个提示:
如果您不在托管环境中(= 如果它是您自己的服务器并且您可以.htaccess文件),尝试使用
RewriteLog
指令:它可以帮助您追踪此类问题:我的最喜欢的检查正则表达式的工具:
http://www.quanetic.com/Regex (不要忘记选择 ereg(POSIX) 而不是 preg (PCRE)!)
Here's a "cleaner" version of your rewriterules.
Tell me if they work.
And if that's not enough:
Two hints:
If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the
.htaccess
files), try to use theRewriteLog
directive: it helps you to track down such problems:My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)