0

I'm using a large number of Redirect 301's which are suddenly failing on a new webserver.

We're in pre-production tests on the new webserver, prior to migrating the sites, but some sites are failing with 500 Internal Server Error. The content, both databases and files, are mirrored from the old to the new server, so we can test if all sites work properly.

I traced this problem to mod_alias' Redirect statement, which is used from .htaccess to redirect visitors and search engines from old content to new pages.

Apparently the Apache server requires the destination to be a full url, including protocol and hostname.

Redirect 301  /directory/  /target/                        # Not Valid
Redirect 301  /main.html   /                               # Not Valid
Redirect 301  /directory/  http://www.example.com/target/  # Valid
Redirect 301  /main.html   http://www.example.com/         # Valid

This contradicts the Apache documentation for Apache 2.2, which states:

The new URL should be an absolute URL beginning with a scheme and hostname, but a URL-path beginning with a slash may also be used, in which case the scheme and hostname of the current server will be added.

Of course I verified that we're using Apache 2.2 on both the old and the new server. The old server is a Gentoo box with Apache 2.2.11, while the new one is a RHEL 5 box with Apache 2.2.3.

The workaround would be to change all paths to full URL's, or to convert the statements to mod_rewrite rules, but I'd prefer the documented behaviour.

What are your experiences?

Martijn Heemels
  • 7,438
  • 6
  • 39
  • 62

3 Answers3

1

It appears that this behavior varies between Apache versions and distributions, and it contradicts the Apache documentation (as stated in the question). Very annoying. I could find no obvious pattern to which version supports which behaviour.

Rewriting all Redirects to similar RewriteRules does the trick since RewriteRules are much more versatile, but at the expense of readability.

Martijn Heemels
  • 7,438
  • 6
  • 39
  • 62
1

When Redirect 301 URL-path URL-path fails, you can try RedirectMatch 301 URL-path URL-path. It worked for me on a server where Redirect without a full URL as destination was throwing 500 Internal Server error: Redirect to non-URL.

0

you have to use a redirect with the full name of the new webserver. because the new webserver is on a new server, apache on your old server can't tell were to go only by the url-path. you have to tell on which machine it is hosted when it is not the same.

you should consider another point: Will your old wevserver be shutdown some time in the future? will your new server take over the dns name of the old one?

perhaps you should think about just changing dns after migrating all website to the new server.

Christian
  • 4,645
  • 2
  • 23
  • 27
  • I should have clarified that I'm not using Redirect to point from the old server to the new. The content has been mirrored to the new server and once done we will switch DNS to the new one. The problem just appeared when testing the server in pre-production, with the mirrored content. – Martijn Heemels Jan 12 '10 at 11:00
  • have you checked that on the new server scheme and hostname are set right (i guess some temporary dns name for testing), so apache uses the right ones when doing the redirect? does the apache error log give some hints? – Christian Jan 12 '10 at 11:11