1
votes

I have two domain names pointing to the same server and being accepted by the nameservers. My host calls this a domain alias. An older WordPress blog, olddomain.com, hosted a blog while a newer domain, newdomain.com, now hosts a revamped blog AND a portfolio site.

My client wants to capture his old blog traffic and allow those to pass through. That all works fine already because of the domain alias. In other words, without me doing anything to the .htaccess file, this internal redirect already happens:

http://olddomain.com/year/month/day/post-slug/ already redirects to: http://newdomain.com/year/month/day/post-slug/

The problem is that we also need to redirect the olddomain.com homepage traffic to the new landing page of the blog. The old site's homepage was the blog, but the new site's homepage is the personal portfolio. Therefore, what I need htaccess to do is:

  • Retain the current domain name pass through as noted above, and made possible by the name servers and my hosts domain alias settings
  • Take any traffic that was intended for the old homepage and redirect to the new blog landing page, which looks like this:

olddomain.com(nothing else here) needs to redirect to newdomain.com/blog/(nothing else here)

The problem that I am having is that any solution that I put in place to do the above redirect messes with the natural redirection that is happening for the blog posts themselves. I can't quite get it to the point where I can have both at the same time. The htaccess also needs to retain the standard WordPress chunk that rewrites for the index.php file.

This is what I have currently, which rewrites olddomain.com to newdomain.com/blog/, but sends all other old traffic to specific blog posts back to the homepage instead of allowing the internal domain alias redirect to happen.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} (www.)?olddomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/blog/ [R=302,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Thanks.

1

1 Answers

1
votes

You can replace your existing code with these rules:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# redirect only landing page to new site's /blog/ URI
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+[?\s]
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^/?$ http://newdomain.com/blog/ [R=307,NE,L]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

Test it from a new browser or after clearing your browser cache.