[英]How to have a load of redirect rules end with a rule that catch all for everything else NOT matching wordpress backend for apache htaccess
oldwebsite.com/about
和oldwebsite.com/about/
转到newwebsite.com/about
oldwebsite.com
和oldwebsite.com/
转到newwebsite.com
oldwebsite.com/wp-admin
保持原样,因为我需要访问wordpress admin后端 oldwebsite.com/everything-else
转到newwebsite.com/blog/everything-else
我将Redirect 301 ...
用于1st 2要求。
他们运作良好。
然后当我添加
RewriteRule !^wp-admin($|/) http://newwebsite.com/blog%{REQUEST_URI} [L,R=301]
从其他地方来3和4
当我尝试访问wp-admin时,它不起作用,因为我被重定向到newwebsite.com/blog/wp-login.php......
我应该使用L标志来确保一旦规则匹配,它将从htaccess
退出。
WordPress依赖于很多文件和子文件夹作为后端。 需要使用正则表达式(wp\\-.*)
来捕获所有情况。
# when whatever comes after oldwebsite.com/ matches about OR about/
# go to ...
# the L makes sure once this rule matches, stop checking the rest.
# the 301 is for the redirection status code which is good for SEO
# read https://moz.com/learn/seo/redirection
RewriteRule ^about($|/) http://newwebsite.com/about [R=301,L]
# same treatment for the index page
RewriteRule ^($|/) http://newwebsite.com [R=301,L]
# when whatever comes after oldwebsite.com/ AND does NOT match wp-{wildcard here....}
# take that whatever and append to http://newwebsite.com/blog/
# and then redirect there using status code 301 and if this rule is true, stop any further
RewriteRule !^(wp\-.*) http://newwebsite.com/blog%{REQUEST_URI} [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.