简体   繁体   English

MOD重写基于URI段的路由(WordPress的永久链接)

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

Wordpress Experts: WordPress专家:

So, my wordpress instance is currently set to use friendly urls. 因此,我的wordpress实例当前设置为使用友好的网址。 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. 这基本上意味着:将所有内容发送到index.php进行调度。

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. 我需要做的是,每当有人访问我的页面/促销时,我将uri的其余部分发送到该控制器(这是通过模板名称:Promo附加到页面的文件promo.php),但仍然需要通过index.php通过管道进行操作。

In a nutshell, I want /promo/fakecompany to technically behave like this to wordpress: index.php?page=promo&fakecompany 简而言之,我希望/ promo / fakecompany在技术上像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 ie a dynamic kind of this: 甚至重定向将占用/ promo以外的任何内容的第二段,并从中创建查询字符串,即这种动态形式:

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 您当前的规则说:将非常规文件或目录以外的任何内容重定向到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) 应该有效(前提是您将其放在当前规则之前)

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

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