繁体   English   中英

如何拥有大量的重定向规则,最后以一个规则捕获所有与apache htaccess的wordpress后端不匹配的其他所有内容

[英]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

需要什么

  1. oldwebsite.com/aboutoldwebsite.com/about/转到newwebsite.com/about
  2. oldwebsite.comoldwebsite.com/转到newwebsite.com
  3. oldwebsite.com/wp-admin保持原样,因为我需要访问wordpress admin后端
  4. 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......

关键点1

我应该使用L标志来确保一旦规则匹配,它将从htaccess退出。

重点2

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM