Wasteland
Wasteland

Reputation: 5389

redirection between two domains based on regex

We have two domains on two different hosts (both wordpress installations):

oldsite.com
newsite.com

A lot of articles were mirrored on a new site with the same title but a different url structure:

eg:

oldsite.com/posts/article-about-cats
newsite.com/news/article-about-cats

another scenario:

oldsite.com/posts/article-about-cats
newsite.com/news/2018/08/09/article-about-cats

Assuming the title of the article is the same, what would a rewrite rule(s) be in .htaccess on the oldsite server?

Upvotes: 0

Views: 166

Answers (1)

anubhava
anubhava

Reputation: 785481

As mentioned in my comment above that you cannot have generic rule for second scenario where target URL has dynamic part such as /2018/08/09/, which is not part of original URL.

For the first scenario, you can use this rule in site root .htaccess:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?oldsite\.com$ [NC]
RewriteRule ^posts/(.*)$ http://newsite.com/news/$1 [L,NC,NE,R=301]

Upvotes: 1

Related Questions