[英]How should I do a 301 redirect / rewrite on my WordPress site?
I am migrating my WordPress website from a sub-domain to the main domain: 我正在将WordPress网站从子域迁移到主域:
So from blog.example.net
to example.net
. 因此,从
blog.example.net
到example.net
。
A typical post URL on the sub-domain would be: 子域上的典型帖子URL为:
https://blog.example.net/mypost
A typical post on the new domain would be the same: 新域上的典型帖子是相同的:
https://example.net/mypost
The WordPress permalink settings are the same on both. 两者的WordPress永久链接设置相同。 If I add this Rewrite rule to my .htaccess file on
blog.example.net
: 如果我将此重写规则添加到
blog.example.net
上的.htaccess文件中:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog.example.net [NC,OR]
RewriteRule ^(.*)$ https://www.example.net/$1 [L,R=301,NC]
then page is redirected to: 然后页面被重定向到:
https://www.example.net/YYYY/MM/DD/mypost
and the page is not found on the new domain: 并且在新域上找不到该页面:
How do I remove the /YYYY/MM/DD/
from the URL on https://example.net/mypost
? 如何从
https://example.net/mypost
上的URL中删除/YYYY/MM/DD/
?
Try this if there is a date in URI like /2018/03/07
: 如果URI中有一个日期,例如
/2018/03/07
请尝试以下操作:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?blog.example.net [NC]
RewriteCond %{THE_REQUEST} \s/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*)\sHTTP.*$
RewriteRule ^ https://www.example.net/$1 [L,R=301]
If it is exactly like YYYY/MM/DD
, replace with this : 如果与
YYYY/MM/DD
完全一样,请替换为:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?blog.example.net [NC]
RewriteCond %{THE_REQUEST} \s/[Y]{4}/[M]{2}/[D]{2}/(.*)\sHTTP.*$
RewriteRule ^ https://www.example.net/$1 [L,R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.