Redirect 301 fails with a path as destination
Posted
by Martijn Heemels
on Server Fault
See other posts from Server Fault
or by Martijn Heemels
Published on 2010-01-12T10:17:12Z
Indexed on
2010/04/13
12:13 UTC
Read the original article
Hit count: 294
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?
© Server Fault or respective owner