Issue with redirection of a folder with mod_alias
-
21-09-2019 - |
Question
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.
Solution
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
OTHER TIPS
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 targetURL
. Additional path information beyond the matchedURL-Path
will be appended to the targetURL
.
Try RedirectMatch
instead:
RedirectMatch 301 ^/team/ /team.html