mod 根据 uri 段重写路由(wordpress 永久链接)
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当前的规则规定:将任何非常规文件或目录的内容重定向到index.php
对于您的请求:
或
应该有效(前提是您将其放在当前规则之前)
Your current rules say : redirect anything that is not a regular file or a directory to index.php
For your request :
or
Should work (provided you place it before the current rules)