JohnnyAce
JohnnyAce

Reputation: 3739

Redirect all the .html files to old site with htaccess

I want to redirect all the files that end with .html to a the old site folder, currently my htaccess looks as follows:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # RedirectMatch 302 /(.+?).html$ http://superawesomedomain.com/old/$1.html [L] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>

But with my condition RedirectMatch 302 when I apply it gets to http://superawesomedomain.com/old/old/old/old/old/old...old/old/old...old/old/old/ until it breaks the browser :(

Any ideas on how to make the redirection?

Thank you!

Upvotes: 1

Views: 39

Answers (1)

anubhava
anubhava

Reputation: 785276

You can use these rules:

RewriteEngine On
RewriteBase /

RewriteRule ^((?!old/).+?\.html)$ /old/$1 [L,NC,R=302]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
  • Don't use RedirectMatch with other mod_rewrite rules
  • Make sure you're not redirecting when URI already starts with /old/ to stop redirection loop

Upvotes: 1

Related Questions