What more could you want?
Intro to Apache Redirects
I came across an issue where a customer needed education on using Redirect in the Apache config. Particularly, the redirects were being configured through webmin (which, btw, does an amazing job of mangling the httpd.conf file!). I though somebody may find it useful, and cleaned it up. The names or websites have been changed to protect the innocent or the not-so-innocent.
Here is the syntax that webmin placed into the Apache config on your server for various redirects:
# grep ^Redirect /etc/httpd/conf/httpd.conf
Redirect http://kubrick.fruella.com “https://secure3.paymelater.net/csr/default.asp”
Redirect http://kubrick “https://secure3.paymelater.net/csr/default.asp”
Redirect http://epay.fruella.com “https://secure3.paymelater.net/fruella/”
Redirect http://epay.fruelladev.com “https://secure3.paymelater.net/fruella/”
Redirect http://epay “https://secure3.paymelater.net/fruella/”
Redirect 301 epay “https://secure3.paymelater.net/fruella/”
RedirectPermanent epay “http://www.gooboodle.com”
RedirectPermanent e-pay “http://www.gooboodle.com”
These will not work:
Redirect http://kubrick “https://secure3.paymelater.net/csr/default.asp”
Redirect http://epay “https://secure3.paymelater.net/fruella/”
Redirect 301 epay “https://secure3.paymelater.net/fruella/”
RedirectPermanent epay “http://www.gooboodle.com”
RedirectPermanent e-pay “http://www.gooboodle.com”
The reason that these won’t work is because you aren’t giving them a URL or URI to redirect. A proper 301 redirect (which is the most common type, and properly what you need) is as such:
Redirect 301 / http://www.example.com
This will take the root of the site (“/”) and redirect it to www.example.com. So, if your site is domain.com, and you visit domain.com in a browser, you’ll be redirected to www.example.com. The URL in the browser will change, and a new request to Apache is made for www.example.com.
If you have a particular page that needs to be redirected, the syntax would be similar:
Redirect 301 /store/secure/checkout.php http://www.paymesometime.com/
… or something similar to that.
This will take requests for domain.com/store/secure/checkout.php and redirect them accordingly.
Through webmin, you want to configure these as follows:
The first case:
From: /
Status: 301
To: http://www.example.com
The second case:
From: /store/secure/checkout.php
Status: 301
To: http://www.paymesometime.com/
Alternatively, in the “From:” section, you can specify a full URL, similar to the “To:” section, but I would recommend that it is easier to read them if you differentiate the syntax.
As for the entries in your configuration, here is an outline of what’s incorrect:
Incorrect:
Redirect http://kubrick.fruella.com “https://secure3.paymelater.net/csr/default.asp”
Correction:
Redirect 301 http://kubrick.fruella.com “https://secure3.paymelater.net/csr/default.asp”
You have provided a URL to redirect from (you could substitute with “/” in this case, because it’s the base URI). You have specified a URL to redirect to. You have NOT, however, provided a status. If this rule is updated in webmin with a “Status:” of 301, then it will work.
Incorrect:
Redirect http://kubrick “https://secure3.paymelater.net/csr/default.asp”
Correction:
Redirect 301 http://kubrick.fruella.com “https://secure3.paymelater.net/csr/default.asp”
This is incorrect because there is no status and because http://kubrick is not a fully qualified domain name.
Incorrect:
Redirect 301 epay “https://secure3.paymelater.net/fruella/”
Correction:
Redirect 301 / “https://secure3.paymelater.net/fruella/”
All of the parts including From:, To:, and Status: are here, but “epay” is neither a URI (which begins with a “/” character) nor a fully qualified domain name.
Redirects will be evaluated top to bottom, so if you have more than one that matches (such as two that redirect from “/” to another URL) then only the first will be effective, and the second is unnecessary.
This should be enough to get you started with redirects in Apache.
/cs
| Print article | This entry was posted by chuck on January 20, 2009 at 6:36 pm, and is filed under Uncategorized. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |