我的.htaccess中有重定向的问题非常奇怪。
我设定的规则是:
RewriteRule ^([a-zA-Z0-9\-]*)/$ ?mode=book&permalink=$1它匹配多个单词短语: http://www.fernwoodpublishing.ca/About-Canada-Youth-and-Children/
和单词短语: http://www.fernwoodpublishing.ca/Kaandossiwin/
但是,如果它与那些单字短语匹配,没有任何连字符,则反向引用不会正确传递。 那么,上面的例子应该去哪里
?mode=book&permalink=Kaandossiwin这将正常工作,而不是去
?mode=book&permalink=这只是创造了一大堆错误并打破了一些东西。
我尝试了一种方法来解决这个问题,似乎没有任何帮助。 任何对htaccess更有经验的人都知道为什么在这些特定情况下不返回反向引用? (我已经用其他示例测试了它并且经历了相同的问题,因此我确信它在所有情况下都匹配,但只在匹配包含连字符的情况下返回后引用。
非常感谢!
I'm having a really strange issue with a redirect in my .htaccess.
The rule I have set up is:
RewriteRule ^([a-zA-Z0-9\-]*)/$ ?mode=book&permalink=$1It matches both multi-word phrases: http://www.fernwoodpublishing.ca/About-Canada-Youth-and-Children/
and single-word phrases: http://www.fernwoodpublishing.ca/Kaandossiwin/
However, when it does match those single-word phrases, without any hyphens, the backreference isn't passed through properly. So, where the above example SHOULD go to
?mode=book&permalink=Kaandossiwinwhich would work correctly, it instead goes to
?mode=book&permalink=which just creates a whole slew of errors and breaks stuff.
I've tried a variant of ways to fix this, and nothing seems to be helping. Anyone more experienced with htaccess have any idea why the back-reference isn't being returned in these specific cases? (I've tested it with other examples and have experienced the same problem precisely, so I'm certain that it's matching in all cases, but only returning the back-reference in those cases where the match contains hyphens.
Thanks so much!
最满意答案
请尝试以下方法。 我认为分组是畸形的。
RewriteRule ^([\w-]+)/$ ?mode=book&permalink=$1我还建议为你的链接添加前缀,因为这种URL格式非常宽松。 也就是说它匹配顶级字母数字,下划线或短划线的任何URL。 像下面这样的东西更灵活。
RewriteRule ^book/([\w-]+)/?$ book.php?permalink=$1Try the following. I believe the grouping is malformed.
RewriteRule ^([\w-]+)/$ ?mode=book&permalink=$1I'd also suggest prefixing your link as this URL format is pretty loose. That is to say it matches any URL with alphanumeric, underscore, or dash at the top level. Something like the following is more flexible.
RewriteRule ^book/([\w-]+)/?$ book.php?permalink=$1更多推荐
发布评论