为什么matches[2]在重写规则中不返回任何内容 [英] Why matches[2] does not return anything in rewrite rule

查看:63
本文介绍了为什么matches[2]在重写规则中不返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 URL www.domain.com/some/my-page--woohoo.html 重定向到 www.domain.com/index.php?pagename=my-page

I'm trying to redirect URL www.domain.com/some/my-page--woohoo.html to www.domain.com/index.php?pagename=my-page

我有这个规则通过 add_action('init', 'create_rewrite_rule', 1, 0);

I have this rule that is attached to init via add_action('init', 'create_rewrite_rule', 1, 0);

add_rewrite_rule('^.*\/(.*)--woohoo\.html$', 'index.php?pagename=$matches[1]', 'top');

调用 www.domain.com/some/my-page--woohoo.html 返回 404,但是什么时候改成规则

Calling www.domain.com/some/my-page--woohoo.html returns 404, but when is rule changed to

add_rewrite_rule('^.*\/(.*)--woohoo\.html$', 'index.php?pagename=my-page', 'top');

一切正常.

似乎 $matches[1] 什么都不返回 :-( 为什么?

It seems that $matches[1] returns nothing :-( Why?

感谢您的帮助!

推荐答案

如果有人会解决这个问题,我还没有找到真正的解决方案(我尝试了很多小时)所以我不得不通过常规的 htaccess 处理它重定向,即使它不是最佳的(就我而言).

If anybody will ever deal with this, I haven't found real solution (I tried MANY things for hours) so I had to deal with it thru regular htaccess redirects, even though it is not optimal (in my case).

如果你找到了解决方案,请写在这里,否则我认为它是WP中的一个错误.

If you found a solution, please write it here, otherwise I consider it as a bug in WP.

这篇关于为什么matches[2]在重写规则中不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆