开发者

mod rewrite to route based on a uri segment (wordpress permalink)

开发者 https://www.devze.com 2023-02-27 04:59 出处:网络
Wordpress Experts: So, my wordpress instance is currently set to use friendly urls.My current rewrite rules look something like开发者_开发百科 this:

Wordpress Experts:

So, my wordpress instance is currently set to use friendly urls. My current rewrite rules look something like开发者_开发百科 this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Which basically means: send everything to index.php for dispatching.

What I NEED to do, is whenever someone accesses my page /promo, I send the rest of the uri to that controller (which is a file promo.php attached to the page via Template Name: Promo) but it would still need to be piped through the index.php to do that.

In a nutshell, I want /promo/fakecompany to technically behave like this to wordpress: index.php?page=promo&fakecompany

Or even a redirect that would take the second segment of anything beyond /promo and create a querystring out of it i.e. a dynamic kind of this:

Redirect 301 /promo/fakecompany /promo/?fakecompany
Redirect 301 /promo/fakecompany/referpage /promo/?fakecompany&referpage

Is there a way to do this? Or possibly a more elegant solution? Worst comes to worse, I'm just going to have to hardcode in a redirect for the moment:

Thanks in advance.


Your current rules say : redirect anything that is not a regular file or a directory to index.php

For your request :

RewriteRule ^/promo/([^/]+)$ index.php?page=promo&$1 [L]

or

RewriteRule ^/promo/([^/]+)/([^/]+)/$ /promo/?$1&$2

Should work (provided you place it before the current rules)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号