Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess - move site from .html to .php, but exclude a folder

I've got a new site, and put the old version of the site in an /old folder.

The new site has the same page names as the old one, except they all now have a .php extension.

I've got the following rule for SEO to direct all the .html files to .php

RedirectMatch 301 (.*)\.html$ http://www.mysite.com$1.php

But I still need to be able to access everything in the /old folder - the redirect is obviously redirecting the files in here too (e.g. mysite.com/old/mypage.html is going to mysite.com/old/mypage.php - I need the .html version)

I've tried to find out for myself, but I'm not sure about all the RedirectXYZ commands.

Any ideas?

like image 323
Josh Avatar asked Dec 04 '25 10:12

Josh


1 Answers

You can achieve this using negative lookahead:

RedirectMatch 301 ^(?!/old)(.*)\.html$ http://www.mysite.com$1.php

(?!/old) rejects a match containing the string /old at this position. We use ^ to restrict this to the beginning of the string being matched against.

like image 152
moinudin Avatar answered Dec 07 '25 01:12

moinudin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!