views:

33

answers:

2

Hey All.

I need to do a mass 301 Redirect for all pages ending with .html for my site. I am looking to move all the old .html files to a sub-folder ir.

RedirectMatch 301 (.*)\.html$ http://www.domain.com/folder/$1.html

When I add this and refresh the browser I get a ton of folder/folder/folder now after the url ie

domain.com/folder//folder/folder/folder.....

Any ideas what could be wrong?

Thanks if you can help

+1  A: 

The problem is, that 'folder/foo.html' also matches the condition of the RedirectMatch and folder is appended again (and again, and again ...)

Therefore you probably need something like this (untested):

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*)\.html$ /folder/$1.html [R=301,L]

The RewriteCond should check that the URI doesn't start with /folder and only if this condition is met, the RewriteRule will be checked.

Unfortunately I haven't any Apache installation available at the moment for testing such things, so you will probably have to try it on your own. But I hope you got the idea.

tux21b
A: 

If your old html files are in the root, I would suggest the following:

RedirectMatch 301 ^([^/]+)\.html$ http://www.domain.com/folder/$1.html
TonyCool