简体   繁体   English

WordPress htaccess重写器,无需更改URL

[英]Wordpress htaccess rewriterule without changing URL

In WordPress I'm using the Events Manager plugin, which uses the /events/subpage path in the URL. 在WordPress中,我使用的是事件管理器插件,该插件在URL中使用/ events / subpage路径。

I need to tweak things slightly so that /courses/subpage rewrites to /events/subpage ie the content of /events/subpage is shown when going to /courses/subpage. 我需要稍微调整一下内容,以便/ courses / subpage重写为/ events / subpage,即,在转到/ courses / subpage时显示/ events / subpage的内容。 The URL should stay as /courses. 该网址应为/ courses。

I thought this rule would do it: 我认为这条规则可以做到:

RewriteRule ^courses/?(.*)$ /events/$1 [L]

But the URL changes from /courses to /events so it looks like my rule isn't quite right. 但是URL从/ courses更改为/ events,所以看来我的规则不太正确。

EDIT Strangely I can put anything in place of /courses and it resolves to /events anyway. 编辑奇怪的是,我可以将任何东西替换为/ courses,并且无论如何它都会解析为/ events。 Confused! 困惑!

Think I've cracked it. 认为我已经破解了。

I uninstalled the rewrite plugin and replaced it with Rewrite Rules Inspector. 我卸载了重写插件,并用重写规则检查器替换了它。 Then I added the following to functions.php add_rewrite_rule('^course/([^/]*)/?', 'index.php?event=$matches[1]', 'top'); 然后我将以下内容添加到函数中。php add_rewrite_rule('^ course /([[^ /] *)/?','index.php?event = $ matches [1]','top'); // single event //单个事件

In Rewrite Rules Inspector is said the rule was missing. 在“重写规则检查器”中,该规则缺失。 I flushed the rules using the plugin and everything appears to be working now. 我使用插件刷新了规则,现在一切似乎都可以正常工作了。 It looks like the original rewrite plugin wasn't flushing the rules properly. 看起来原始的重写插件未正确刷新规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM