【问题标题】:Redirect sub-folders to a new folder in WordPress将子文件夹重定向到 WordPress 中的新文件夹
【发布时间】:2018-10-17 09:44:15
【问题描述】:

我一直在努力将旧网址重定向到新网站页面。

目标是重定向许多子文件夹页面,例如: https://www.example.com/news/events/event18

到一个唯一的文件夹:https://www.example.com/focus

在 Wordpress 中使用 htaccess 文件,我试过了:

RedirectMatch 301 /oldfolder1/oldpage1/(.*) /newfolder/$1

结果是:

https://www.example.com/newfolder/oldpage1

另一种方法:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^oldfolder/(.*)$ https://www.example.com/newfolder [R=301,L]

结果是一样的!

我有很多旧网址,我想避免手动 Redirect 301 为所有这些网址。

谢谢帮助。

【问题讨论】:

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


    【解决方案1】:

    一切都会出自/news吗?还是它也会从另一个文件夹中出来?下面的示例将在重写之前检查第一层子文件夹中的两个名称(newsarticles)之一。

    RewriteCond %{DOCUMENT_ROOT}/news%{REQUEST_URI} -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/news%{REQUEST_URI} -d
    RewriteRule ^(.*)$ /focus/$1 [L]
    
    # then check if request is in a different folder like /articles/
    RewriteCond %{DOCUMENT_ROOT}/articles%{REQUEST_URI} -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/articles%{REQUEST_URI} -d
    RewriteRule ^(.*)$ /projects/$1 [L]
    
    # otherwise, blindly rewrite to /news (or do nothing by removing this rule to allow a 404 not found)
    RewriteCond ${REQUEST_URI} !^/news/
    RewriteRule ^(.*)$ /news/$1 [L]
    

    【讨论】:

    • 喜欢那个解决方案!谢谢
    猜你喜欢
    • 1970-01-01
    • 2021-09-08
    • 2014-09-05
    • 2018-09-30
    • 2017-12-05
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 2015-11-22
    相关资源
    最近更新 更多