重定向除root以外的所有页面 [英] redirect all pages except root

查看:82
本文介绍了重定向除root以外的所有页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个WordPress网站分离出来,该网站具有4个特定的博客部分,这些博客部分使用自定义帖子类型构建到自己的个人网站。

I'm trying to separate out a WordPress site that has 4 specific blog sections built with custom post types to their own individual sites.

我的网址看起来像这样:

I have urls that look like:

example.com/site1/postname
example.com/site2/postname

example.com/site1/postname example.com/site2/postname etc

我需要做的是将每个站点下的所有帖子重定向到新站点,同时将根页面保留在原位置。

What I need to do is redirect all the posts under each site out to the new site while leaving the root page where it is.

例如。 com / site1 / postname变为example2.com/postname

So example.com/site1/postname becomes example2.com/postname

,但example.com/site1/需要保留为example.com/site1/

but example.com/site1/ needs to stay as example.com/site1/

其他3个站点相同。希望这是有道理的。

And the same for the other 3 sites. Hope that makes sense.

我有这个功能,可以很好地将帖子重定向到新站点,但是它也可以重定向根目录,因此无法解决

I have this and it works great at redirecting the posts to the new site but it also redirects the root base as well and can't work out what to change to fix that.

RewriteEngine on
RewriteRule ^site1/(.*)$ http://www.example2.com/$1 [L,R=301]


推荐答案

要重定向除所有4个站点的根以外的所有内容,请使用:

To redirect everything except root of all 4 sites use:

RewriteEngine on

RewriteRule ^(site1|site2|site3|site4)/(.+)$ http://$1.com/$2 [L,NC,NE,R=301]

。+ 之后,将确保不匹配这些文件夹的根。

.+ after these sites will make sure to not to match root of these folders.

这篇关于重定向除root以外的所有页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆