Why matches[2] does not return anything in rewrite rule

杀马特。学长 韩版系。学妹 提交于 2019-12-25 17:06:19

问题


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

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');

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');

everything works.

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

Thank you for any help!


回答1:


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).

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



来源:https://stackoverflow.com/questions/35846891/why-matches2-does-not-return-anything-in-rewrite-rule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!