简单的 WordPress 重写规则
我面临着 wordpress / htaccess 问题。这应该非常简单,但它不起作用,我很沮丧。
我的网站以这种方式处理永久链接: http://www.my-site.com/articles/category/title
现在,有一个我称为“特写”的类别,我不希望显示“文章”的 URL。因此,我想
访问http://www.my-site.com/articles/closeup/childCategory/title
使用这样的 URL
中的内容http://www.my- site.com/closeup/childCategory/
我已经编写了一个页面,用于处理在同一页面上显示所有文章的子类别。
所以我写了一个htaccess重写规则如下:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^closeup/(.*) articles/closeup/$1 [L]
</IfModule>
我在一个允许我测试我的htaccess规则的网站上在线测试了htaccess,并且它在那里工作得很好,但在我的博客上却不行。有什么建议吗?
所以整个htaccess是:
# BEGIN BS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^closeup/(.*) articles/closeup/$1
</IfModule>
# END BS
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I'm facing a wordpress / htaccess problem. This should be really simple, but it's not working and I'm getting frustrated.
My site handles permalinks this way: http://www.my-site.com/articles/category/title
Now, there is a category I called 'closeup' for which I don't want the URL to show 'article'. So I would like to access content from
http://www.my-site.com/articles/closeup/childCategory/title
with an URL like this
http://www.my-site.com/closeup/childCategory/
I already wrote a page that handles the child category showing all articles on the same page.
So I wrote an htaccess rewrite rule as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^closeup/(.*) articles/closeup/$1 [L]
</IfModule>
I tested the htaccess online on a website which allowed me to test my htaccess rules, and it works fine there, but not on my blog. Any tip?
So the whole htaccess is:
# BEGIN BS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^closeup/(.*) articles/closeup/$1
</IfModule>
# END BS
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将其添加到 # Begin Wordpress 块上方,它应该可以解决问题:
背景:
ReweriteRule 正在执行您所期望的操作,这是 WordPress 找不到该页面。要根据永久链接查找帖子,Wordpress 使用
或
在您的情况下,即使在 RewrtieRule 之后,URL 也会显示为
WordPress 使用
$_SERVER['REQUEST_URI']
(closeup/childCategory/) 来解析永久链接并返回 404。如果您使用 RewriteRule 在 index.php 之后传递所需的路径,
Wordpress 将找到您的路径信息(因为它尝试首先是
$_SERVER['PATH_INFO']
),因此永久链接将为articles/closeup/childCategory/
If you add this above your # Begin Wordpress block, it should solve the problem:
Background:
ReweriteRule is doing what you expect, it's Wordpress that can't find the page. To find the post based on the permalink, Wordpress uses either
or
In your case, even after the RewrtieRule the URL appears as
Wordpress uses
$_SERVER['REQUEST_URI']
(closeup/childCategory/) to parse the permalink and returns a 404.If you use RewriteRule to pass the desired path after index.php
Wordpress will find your path info (because it tries
$_SERVER['PATH_INFO']
first) so the permalink will bearticles/closeup/childCategory/
为什么不使用 WordPress 的自定义分类功能呢?创建“特写”页面/帖子类型。
Why not use Wordpress's custom taxonomy capability instead? Create a page/post type of "closeup."