【问题标题】:how can i redirect dynamic URL in worpress base on ID in htaccess or wp-config or function.php如何根据 htaccess 或 wp-config 或 function.php 中的 ID 在 wordpress 中重定向动态 URL
【发布时间】:2021-09-28 12:59:04
【问题描述】:

我想将 301 重定向到以下网址

worpress.com/NewsInfoPrint?id=13624

wordpress.com/news/13624/

//数字是WordPress中的ID帖子,我需要所有帖子都这样做,所以数字是动态的

我该怎么做?

【问题讨论】:

    标签: php wordpress url redirect http-status-code-301


    【解决方案1】:

    请试试这个。

    RewriteEngine On  
    RewriteCond %{REQUEST_URI}  ^\/NewsInfoPrint$ 
    RewriteCond %{QUERY_STRING} ^id=([0-9]*) 
    RewriteRule ^(.*)$ \/news/%1/? [R=301,L]
    

    【讨论】:

    • 感谢您的解决方案 Aghilan B。我将此代码放在 htaccess 的第一行并且可以正常工作。祝你好运
    猜你喜欢
    • 1970-01-01
    • 2016-07-02
    • 2014-01-19
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多