开发者

.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

Redire开发者_StackOverflowctMatch 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜