简单的Wordpress RewriteRule

时间:2011-11-09 19:13:47

标签: wordpress .htaccess mod-rewrite

我正面临一个wordpress / htaccess问题。这应该非常简单,但它不起作用,我感到很沮丧。

我的网站以这种方式处理永久链接:http://www.my-site.com/articles/category/title

现在,有一个名为'closeup'的类别,我不希望URL显示'article'。所以我想访问

中的内容

http://www.my-site.com/articles/closeup/childCategory/title

使用这样的网址

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

2 个答案:

答案 0 :(得分:1)

如果你在#Endit Wordpress块上面添加它,它应该可以解决问题:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^closeup/(.*) index.php/articles/closeup/$1 [L]
</IfModule>

背景:

ReweriteRule正在做你期望的事情,它是无法找到页面的Wordpress。要根据固定链接查找帖子,Wordpress使用

$_SERVER['PATH_INFO']

$_SERVER['REQUEST_URI']

在您的情况下,即使在RewrtieRule之后,URL显示为

http://www.my-site.com/closeup/childCategory/

Wordpress使用$_SERVER['REQUEST_URI'](closeup / childCategory /)来解析永久链接并返回404.

如果使用RewriteRule在index.php

之后传递所需的路径
http://www.my-site.com/index.php?/articles/closeup/childCategory/

Wordpress会找到您的路径信息(因为它首先尝试$_SERVER['PATH_INFO']),因此永久链接将为articles/closeup/childCategory/

答案 1 :(得分:0)

为什么不使用Wordpress自定义分类功能呢?创建“关闭”的页面/帖子类型。