【问题标题】:Wordpress. Rewrite url when on custom taxonomyWordPress。在自定义分类时重写 url
【发布时间】:2013-02-17 14:09:17
【问题描述】:

这是一个 wordpress 网站。我正在使用一个名为 media tags 的插件。此插件创建一个名为“媒体标签”的自定义分类法来显示已标记的媒体。这些页面的 url 当前是 domain/blog/media-tags/results

我想删除博客部分只有在媒体标签页面上。所以我最终得到:

domain.com/media-tags/results

但标准的博客文章、类别和标签仍然保留 blog 部分的 url:

domain.com/blog/cat/post-title、domain.com/blog/cat、domain.com/tag/post-tag

请问可以吗?

【问题讨论】:

    标签: wordpress .htaccess url-rewriting custom-taxonomy


    【解决方案1】:

    我假设您的 .htaccess 文件只需要一个 sn-p。

    RewriteEngine on
    
    # condition to avoid recursion:
    RewriteCond %{REQUEST_FILENAME} !blog
    # your rewrite rule:
    RewriteRule media-tags blog/media-tags
    

    当服务器收到对domain.com/media-tags/results的请求时,它会将目标URL重写为domain.com/blog/media-tags/results

    我猜您还必须配置插件以将 URL 指向服务器的根目录。来自Media Tags plugin homepage

    您还可以将此“/media-tags/”网址参数更改为您喜欢的内容,例如“/gallery/”。为此,请登录 wp-admin 并转到“设置”下的“永久链接”页面。在页面底部,您将看到 Media-Tag 的输入字段。只需输入您的偏好并更新页面。

    【讨论】:

    • 谢谢克拉帕斯,我想你可能有点误解了我的问题。我已经有 domain.com/blog/media-tags/results 显示标记的媒体,但这不是我想要的。我想从“媒体标签”页面(并且只有“媒体标签”页面)中删除“博客”字样。在其他标准博客页面(帖子、类别、标签)上时,我不想从 URL 中删除“博客”。希望这更清楚一点?
    • @user2051970 如果你想重定向用户,例如domain.com/blog/media-tags/results 被重定向到 domain.com/media-tags/results 您需要额外的重定向规则,但您的服务器仍需要上述规则才能找到内容。
    • 谢谢克拉帕斯。请问重定向规则怎么写?
    猜你喜欢
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    • 1970-01-01
    • 1970-01-01
    • 2019-09-17
    相关资源
    最近更新 更多