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?
Answer
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.
No comments:
Post a Comment