views:

68

answers:

2

Another question following on from this thread. The only remaining item that I can't solve is that there is a listing for an now non-existent folder '/team/', but if I add this into my .htaccess file, it breaks all other .htaccess entries for files in that folder, i.e.

redirect 301 /team/ /team.html
redirect 301 /team/joe_bloggs.htm /team.html
redirect 301 /team/joe_bloggs.html /team.html
redirect 301 /team/bill_smith.htm /team.html
redirect 301 /team/bill_smith.html /team.html

If I then attempt to visit /team/joe_bloggs.htm, it takes me to

/team.html/joe_bloggs.htm

If I can fix this, it may help me understand how to resolve my original question and reduce the huge listing of redirect pages in my .htaccess file, so any help gratefully received.
A very merry Christmas to everyone, and a happy new year too.

Thanks Martin

A: 

The Redirect directive works on path prefixes. And in this case the path prefix used in your first directive (/team/) matches and the rest of the path is appended to the new URL path.

[…] any request beginning with URL-Path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-Path will be appended to the target URL.

Try RedirectMatch instead:

RedirectMatch 301 ^/team/ /team.html
Gumbo
Thanks for the advice.<br>Cheers, and a happy new year to you<br>Martin
Martin S
+1  A: 

You need to change the order, and put "redirect 301 /team/ /team.html" at the end. It reads line to line and if it finds something fits, it replaces it.

Furthermore, I think you need to learn to add, ^ and $ characters. ^ means, the expression should begin, and $ means the expression should end. So, ^/team/$ means, it should be exactly /team/ and it wont match /team/joe_bloggs.htm

marvin
Thanks for the advice, and tip. I'll implement them straight away.<br>Cheers, and a happy new year to you<br>Martin
Martin S