.htaccess规则匹配新URL的一部分,并用作旧URL的查询字符串
我正在尝试匹配URL的一部分,然后使用匹配的表达式将其附加到旧URL的查询字符串末尾。
行
RewriteRule ^league/([^/]*)$/matches/? index.php?page_id=1074&league=$1
我在.htaccess
中都有以下 想要([^/]*)$
出现在$ 1
本质上是如此:/lemay/29/Matches/
将指向<代码> index.php?page = 1074&amp; loague = 29
有人可以告诉我我在做什么错吗? :)
I am trying to match part of a URL and then use the matched expression to append onto the end of a query string from the old URL.
I have the following line in .htaccess
, once I've worked out what I'm doing wrong I'll be able to fix the rest so for now I will just focus on the following line:
RewriteRule ^league/([^/]*)$/matches/? index.php?page_id=1074&league=$1
I would like ([^/]*)$
to appear where $1
is
So essentially: /league/29/matches/
would point to index.php?page=1074&league=29
Can anyone please tell me what I am doing wrong? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$
(串联锚定)在subpattern之后导致正则表达式失败。您还应该在此处使用
+
量词(1个或更多)。您还缺少在正则末尾的串联锚点($
)(否则thailing/?
是多余的)。尽管您不应该在重写上真正使Taild Slash可选,因为它可能会为您打开重复的内容。 (您应该重定向以附加/删除落后的斜线以改用URL。)您还缺少l
flag在Rewriterulelule
上。试试以下操作:
尽管您只期望数字(如示例中),那么您应该与数字匹配,而不是任何东西。因此,以下内容可能“更”正确:
The
$
(end-of-string anchor) after the subpattern([^/]*)$
, in the middle of the regex, does not make sense here and will cause the regex to fail. You should also be using the+
quantifier here (1 or more). You are also missing the end-of-string anchor ($
) at the end of the regex (otherwise the trailing/?
is superfluous). Although you shouldn't really make the trailing slash optional on the rewrite as it potentially opens you up for duplicate content. (You should redirect to append/remove the trailing slash to canonicalise the URL instead.) You are also missing theL
flag on theRewriteRule
.Try the following instead:
Although, if you are expecting digits only (as in your example) then you should be matching digits, not anything. So, the following is perhaps "more" correct: