【问题标题】:Redirect URL without trailing post id using .htaccess使用 .htaccess 重定向 URL 而不使用尾随帖子 ID
【发布时间】:2021-03-22 13:26:09
【问题描述】:

我有一个场景,我需要使用 .htaccess 重定向所有 URL 或 wordpress,而不用尾随帖子 ID

例子:

https://example.com/chapter/subject-origin-chapter/1223https://example.com/chapter/subject-origin-chapter

https://example.com/subject/subject-physics/38957https://example.com/subject/subject-physics

也欢迎其他解决方案。

当前的 .htaccess 是:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

【问题讨论】:

  • 请在您的问题中与您分享您现在拥有的 htaccess 规则文件。
  • @RavinderSingh13 它通常的 wordpress .htaccess 没有任何添加。但是,让我将此添加到我的问题中。
  • 只要RewriteRule ^((chapter|subject)/.*)/[0-9]+ $1 [R=301,L] 就可以了。当然要放在一般的 WP 重写之前。

标签: wordpress .htaccess url redirect http-status-code-301


【解决方案1】:

我找到了一个解决方案:

RewriteRule ^chapter/([a-zA-Z0-9-]+)/(\d+)$ /chapter/$1 [L, R=301]
RewriteRule ^subject/([a-zA-Z0-9-]+)/(\d+)$ /subject/$1 [L, R=301]

【讨论】:

    猜你喜欢
    • 2020-05-03
    • 1970-01-01
    • 2021-05-21
    • 2014-05-25
    • 2015-06-02
    • 2017-06-04
    • 2013-01-24
    • 2013-12-05
    相关资源
    最近更新 更多