【问题标题】:How to redirect to new URL in wordpress?如何重定向到 wordpress 中的新 URL?
【发布时间】:2014-01-13 02:12:48
【问题描述】:

我已将 WordPress 帖子(不是页面)的 URL 结构更改为:

example.com/archive/post-id

到:

example.com/post-name

所以当任何用户打开example.com/archive/post-id时,我需要重定向到example.com/post-name

一些网站把我的旧链接放到他的网站上,所以任何用户点击这个链接,它是打开的旧链接。不是真的。

我需要重定向到新链接

我想通过 .htaccess 或插件将旧结构 /post/ 重定向到新结构。

编辑: 我搜索我的问题并查看此代码:

add_action( 'import_done', 'wordpress_importer_init' );

add_action( 'init', 'old_links' );
function old_links(){
    add_rewrite_rule('^archives/([^/]*)/?','index.php?p=$matches[1]','top');
}

现在我需要打开新链接而不是旧链接。

打开时

example.com/archive/post-id我需要用example.com/post-name替换它

【问题讨论】:

    标签: php wordpress .htaccess redirect


    【解决方案1】:

    您可以将此规则放在您现有的 WP 规则之前(就在 RewriteBase 行下方):

    RewriteRule ^archive/(.+)$ $1 [NC,R=301,L]
    

    【讨论】:

    • 我正在编辑我的文件,但仍然找不到页面# 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] RewriteRule ^archive/(.+)$ $1 [NC,R=301,L] </IfModule> # END WordPress
    • 我在回答中明确提到了在您现有的 WP 规则之前,但在 WP 规则之后仍然有 mu 建议规则。将我的规则放在RewriteBase / 行的下方。
    • 我这样做了,但仍然没有找到页面<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^archive/(.+)$ $1 [NC,R=301,L] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
    猜你喜欢
    • 1970-01-01
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 2020-05-02
    • 1970-01-01
    相关资源
    最近更新 更多