mod 根据 uri 段重写路由(wordpress 永久链接)

发布于 2024-11-02 07:35:32 字数 781 浏览 0 评论 0原文

WordPress 专家:

所以,我的 WordPress 实例当前设置为使用友好的 URL。我当前的重写规则看起来像这样:

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

这基本上意味着:将所有内容发送到 index.php 进行调度。

我需要做的是,每当有人访问我的页面 /promo 时,我都会将 uri 的其余部分发送到该控制器(这是通过模板名称:Promo 附加到页面的文件 promo.php),但它仍然需要通过index.php 进行管道传输来做到这一点。

简而言之,我希望 /promo/fakecompany 在技术上对 wordpress 的行为如下:index.php?page=promo&fakecompany

或者甚至是一个重定向,它将采用 /promo 之外的任何内容的第二段并从中创建一个查询字符串,即一种动态的:

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

有办法做到这一点吗?或者可能有更优雅的解决方案?最糟糕的是,我暂时必须在重定向中进行硬编码:

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巷子口的你 2024-11-09 07:35:32

您当前的规则规定:将任何非常规文件或目录的内容重定向到index.php

对于您的请求:

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

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

应该有效(前提是您将其放在当前规则之前)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文