Things look quiet here. But I've been doing a lot of blogging at
dan.langille.org because I prefer WordPress now.
Not all my posts there are FreeBSD related.
I am in the midst of migrating The FreeBSD Diary over to WordPress
(and you can read about that here).
Once the migration is completed, I'll move the FreeBSD posts into the
new FreeBSD Diary website.
Redirecting URL requests with Apache19 January 2000
This article shows a quick and easy way to deal with URLs that have
changed to another server. I used this for my website when I split it up into four
different sites.
What does a redirect do?
A redirect allows you to specify that a requested document is no
longer at the specified URL and provide the new and correct URL. This feature is
extremely useful when rearranging a website. I also consider such redirects to be a
courtesy to the users of the website. It is also a selfish act upon the part of the
website owner. I mean, I want you to find what you want. So it is in my best
interests to make that process as easy as possible. A redirect is one such tool to
ensure your readers find what they want.
At one time, my website contained four
different domains:
freebsddiary.org
freebsddiary.com
racingsystem.com
dvl-software.com
When I split these four domains up into their own websites I wanted the original URLs
to still work, as much as possible. But people were accessing different sections of
the website using the "wrong" URL. That is to say, some of the FreeBSD
Diary data was being fetched with the racingsystem.com domain. I wanted that to
still work. At least until such time as I was able to track down some of the
referring URL and get them updated.
Before the split, people could access the FreeBSD Diary via http://www.racingsystem.com/freebsd/.
After the split, I wanted that URL to still work.
Why bother with redirections?
I can think of two main reasons why redirections are important.
A redirect allows people to find the documents they want. This is especially
important when you consider the bookmarks which people have made. If people can
continue to find the documents they have referenced before, they are much more likely to
continue to use your website.
A redirect allows the URLs contained within search engines to continue to work.
This helps people who use the search engines to look for information. I also
suspect, but I am not positive, that the search engines will notice that the URL has
changed and automatically update their records. I say suspect because the return
code is a 301 (to indicate the permanent move of a file).And more importantly, the
contents of the search engines will still work. More on the details of the 301 code
later.
Example solutions
For these examples, we will use http://www.racingsystem.com/
as our website. We will redirect some incoming requests to other sites.
A redirect
statement can be placed either within virtual host section of httpd.conf or
within a .htaccess file within the website.
Here is my .htaccess file located at http://www.racingsystem.com/freebsd/.
This can also be placed within the virtual host definition of your httpd.conf.
As you can see, if you click on the above link, you wind up back at the FreeBSD Diary
home page. All URLs which specify the the /freebsd directory will be redirected to
the URL specified at the end of the line. Note: at that website I do even more
processing to get the people to the correct URL. See Rewriting
URLs within Apache for more information.
The above was an example of a moved directory. Now let us consider a moved file.
Here's what I do for that instance:
The order of redirects is important. For this example, we are using http://www.freebsddiary.com as our website.
If you have the following two rules, it won't do what you want.