将子文件夹重定向到 WordPress 中的新文件夹
Redirect sub-folders to a new folder in WordPress
我一直在努力将旧网址重定向到新网站页面。
目标是重定向许多子文件夹页面,例如:
https://www.example.com/news/events/event18
到一个独特的文件夹:https://www.example.com/focus
在 Wordpress 中使用 htaccess 文件,我尝试过:
RedirectMatch 301 /oldfolder1/oldpage1/(.*) /newfolder/
结果是:
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]
结果是一样的!
我有很多旧网址,我想避免对所有网址进行手动 重定向 301。
谢谢帮助。
一切都会从/news出来吗?还是它也会从其他文件夹中出来?下面的示例将在重写之前检查第一层子文件夹中的两个名称之一(news 或 articles)。
RewriteCond %{DOCUMENT_ROOT}/news%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/news%{REQUEST_URI} -d
RewriteRule ^(.*)$ /focus/ [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/ [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/ [L]
我一直在努力将旧网址重定向到新网站页面。
目标是重定向许多子文件夹页面,例如: https://www.example.com/news/events/event18
到一个独特的文件夹:https://www.example.com/focus
在 Wordpress 中使用 htaccess 文件,我尝试过:
RedirectMatch 301 /oldfolder1/oldpage1/(.*) /newfolder/
结果是:
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]
结果是一样的!
我有很多旧网址,我想避免对所有网址进行手动 重定向 301。
谢谢帮助。
一切都会从/news出来吗?还是它也会从其他文件夹中出来?下面的示例将在重写之前检查第一层子文件夹中的两个名称之一(news 或 articles)。
RewriteCond %{DOCUMENT_ROOT}/news%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/news%{REQUEST_URI} -d
RewriteRule ^(.*)$ /focus/ [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/ [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/ [L]