简体   繁体   English

我应该如何在WordPress网站上进行301重定向/重写?

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

相关问题 Wordpress 网站上的 301 重定向黑客攻击 - 301 Redirect hack on Wordpress site 如何将我的WordPress网站主页重定向到目标网页,同时允许网站的其余部分不受影响? - How do I redirect my WordPress site homepage to a landing page, while allowing the rest of the site to remain unaffected? 如何做“两个301重定向到一个301重定向” Wordpress - How to do “Two 301 Redirects to One 301 Redirect” Wordpress 如何在WordPress中重定向301 - how to redirect 301 in wordpress 如何将我的Wordpress网站的博客链接重定向到新的子域? - How do I redirect the blog links of my Wordpress site to a new subdomain? 301重定向与异常(在wordpress站点/ htaccess) - 301 redirect with exceptions (in wordpress site / htaccess) .htaccess 301重定向在WordPress网站上不起作用 - .htaccess 301 redirect not working on WordPress site 如何将 index.html 重定向到 Wordpress 站点? - How do I redirect index.html to a Wordpress site? 我如何创建从WordPress(驻留在wsynth上)到Heroku托管的Rails应用的301重定向? - How do I create 301 redirect from WordPress (hosted on wsynth) to a Rails app hosted on Heroku? 301 将 pdf 文件重定向到我的新站点 - 301 redirect pdf files to my new site
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM