【问题标题】:.htaccess rewrite Wordpress category to page.htaccess 将 Wordpress 类别重写为页面
【发布时间】:2013-10-27 11:51:13
【问题描述】:

我的 URL 结构有点问题,因为我使用的是我的 Wordpress 页面的自定义结构。

目前我使用普通页面作为类别。

www.domain.tld/my_page

此页面包含来自普通 Wordpress 类别的所有帖子。页面是使用插件自动生成的。我的问题是当我使用面包屑时,当我进入帖子时,我会得到以下面包屑。

Home > Category > Post

这应该是

Home > Category > Post (where category should link to my_page instead of category)

我可以像这样在 .htaccess 中使用普通的 rewritetrule 来管理这个:

RewriteRule ^category/name_of_category/ http://domain.tld/name_of_category/ [R=301,L]

是否可以在 .htaccess 中进行重写,从 URL 结构中完全删除 /category/?这将使我的结构按应有的方式工作,而无需我每次添加新类别时都在 .htaccess 中添加新规则。

希望有人能提供帮助。

【问题讨论】:

    标签: php wordpress apache .htaccess


    【解决方案1】:
    function kill_category_base ($string) {
       $string = str_replace('category/', '', $string);
       return $string;
    }
    add_filter('category_link', 'kill_category_base');
    
    RewriteRule ^([^/.]+)/(page/([0-9]+)|feed)$ index.php/category/$1/$2 [L]  # redirect category    pages and feeds
    

    在这里找到Remove Categoriy Suffix Permalink

    【讨论】:

    • 谢谢。正是我需要的:)
    猜你喜欢
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    相关资源
    最近更新 更多