简体   繁体   中英

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM