0

On Apache httpd 2.2, my .htaccess is failing when I RedirectPermanent to a file within a subdirectory, but it's fine if the destination file is at the website's root level or is the protocol-and-domain. When the destination file is within a subdirectory, the resulting URL spacelessly repeats the filename many times, after which the host reports a 403 error. In one case, the browser said, "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."; when I clicked in Firefox to Try Again, I got a 403 error.

I already tried including the protocol and the domain (http://cold32.com) in the destination, but that doesn't help. I haven't used RedirectMatch and regular expressions as that would increase maintenance, will if I must, but prefer RedirectPermanent.

Examples of failures:

In .htaccess: either from a file in a subdirectory or from a subdirectory without listing a file to be redirected from (such as if a user traces back through breadcrumbs):

RedirectPermanent /1/overview/1/the-once-over/2/head-neck-and-trunk-are-tops.htm /1/overview/1/the-once-over/1/head-neck-and-trunk-are-tops.htm

RedirectPermanent /1/overview/1/the-once-over/1/ /1/overview/1/the-once-over/1/head-neck-and-trunk-are-tops.htm

Result in browser address bar in both cases: http://cold32.com/1/overview/1/the-once-over/1/head-neck-and-trunk-are-tops.htmhead-neck-and-trunk-are-tops.htmhead-neck-and-trunk-are-tops.htmhead-neck-and-trunk-are-tops.htmhead-neck-and-trunk-are-tops.htmhead-neck-and-trunk-are-tops.htmhead-neck-and-trunk-are-tops.htmhead-neck-and-trunk-are-tops.htm

austinian
  • 1,699
  • 2
  • 15
  • 29
Nick
  • 101
  • possible duplicate of [How to get apache2 to redirect to a subdirectory](http://serverfault.com/questions/9992/how-to-get-apache2-to-redirect-to-a-subdirectory) – austinian Jul 15 '15 at 04:38

1 Answers1

0

Yes, you'll need to use RedirectMatch. You need to change the second rule to this:

RedirectMatch permanent /1/overview/1/the-once-over/1/$ /1/overview/1/the-once-over/1/head-neck-and-trunk-are-tops.htm

The RedirectPermanent you originally wrote is matching the prefix of the url with the first string and replacing it with the second, so each time, it's adding another head-neck-and-trunk-are-tops.htm at the end of any instance of /1/overview/1/the-once-over/1/, then the rule gets triggered again when the redirect goes through, thus all the adds.

Using RedirectMatch, you can specify the end of the string using the $, so /1/overview/1/the-once-over/1/$ will match /1/overview/1/the-once-over/1/ , but won't match /1/overview/1/the-once-over/1/head-neck-and-trunk-are-tops.htm.

Aside: How does this lead to a maintenance increase?

austinian
  • 1,699
  • 2
  • 15
  • 29