1

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?

GiarcTNA
  • 499
  • 2
  • 17

2 Answers2

1

You need to use a RewriteCond in front of all your rules like this:

RewriteCond %{HTTP_HOST} ^(?:www\.)domain\.com$ [NC]

If you want all the following rules to be processed as well DO NOT use the L (last) flag in the RewriteCond statement.

Source: Redirect all urls exactly, just change domain name

Nikolai Tenev
  • 472
  • 3
  • 8
1

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]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks for this, however when I add this in, everything redirects to the new site home page and the 301 rules get ignored completely. – GiarcTNA Aug 28 '17 at 05:30
  • It won't ignore any 301 rules that are **above this rule**. Make sure to clear your browser cache when you test. – anubhava Aug 28 '17 at 06:21