문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top