Craig Craig - 2 months ago 13
Apache Configuration Question

htaccess - Redirecting all traffic to another domain except existing 301's

My htaccess file is filled with 301 redirects like such:

Redirect 301 /old-page.html https://www.example.com/new-page


There are about 100 of these redirects. What I would like to do is redirect all traffic going to the old site to go to the new site excluding the existing 301's

So if someone goes to
old-site.com/old-page.html
it will take them to
new-site.com/new-page
and if someone goes to
old-site.com/random-page.html
it will take them to
new-site.com
- just the home page.

Is it possible to do this using mod_rewrite and mod_alias without rewriting the current 301's?

Answer Source

You can keep all your 301 rules. Just insert this generic 301 rule below your existing rule:

# all existing 301 rules go here

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?old-site\.com$ [NC]
RewriteRule ^ http://new-site.com/? [L,R=301]