0

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

Lee
  • 20,034
  • 23
  • 75
  • 102
  • Give a concrete example of a source URL you're redirecting from and where would you like it to be redirected. – Max Shawabkeh Mar 16 '10 at 11:23
  • OK i I was to give a better example a normal 301 would be RedirectMatch 301 file.html http://www.domain.com/folder/file.html – Lee Mar 16 '10 at 12:30

2 Answers2

1

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
  • 90,183
  • 16
  • 117
  • 101
0

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
  • 1,004
  • 1
  • 6
  • 5