In part 3, we talked about the .htaccess file. What you can do with a .htaccess file (that works only on directory level) can also be done on server level, by specifying instructions in your web server configuration file (often called the httpd.conf file).
The httpd.conf file
The first step, and perhaps the most challenging, is to find your server configuration file and find the block of statements that define the location and behavior of your particular site.
This file is commonly found at
/etc/httpd/httpd.conf, /usr/local/www/conf/httpd.conf or a similar location.
If you can’t find it, ask your system administrator. On a typical server configuration, it might look like this:
<VirtualHost www.mydomain.com>
ServerName www.mydomain.com
ServerAdmin admin@mydomain.com
DocumentRoot /usr/local/www/mydomain.com
ErrorLog logs/mydomain/error_log
TransferLog logs/mydomain/access_log
</VirtualHost>
Your server might have dozens (or more) of these VirtualHost blocks in the configuration file: make sure you find the one for your exact domain name before you make any modifications.
Now that you’ve found this section, you need to add an ErrorDocument handler that specifies the exact numeric code and the name of the file to serve up (or even better, the CGI script to run) when that error is encountered.
Here’s how that might look:
ErrorDocument 404 /errordoc-404.shtml
In this case, when an error 404 is encountered – page or file not found – then the file errordoc-404.shtml will be served up (and notice that you can have server-side includes (SSI) in error documents if you’d like. One trick, though, is to remember that error pages can pop up anywhere in your site hierarchy, so make sure all your graphic references, links to other areas on the site, etc, are absolute references, that they start with ‘/’ or, in extreme cases, ‘http:’.
E. Mod_rewrite.
The Apache Module mod_rewrite provides a rule-based rewriting engine to rewrite requested URLs on the fly.
This module has been described as “the Swiss Army knife of URL manipulation”. But all this functionality and flexibility has its drawback: complexity.
Entire books can be written on this sole module itself and this would be taking us way too far from our scope. I just wanted to mention this for the completeness of this guide as another possibility for URL redirecting.
If you’d like to delve into mod_rewrite, I’d advise you to read the pages on the official site starting at http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
This concludes the sessions about “URL Redirection”. Later, these techniques will come back when we’ll talk about advanced techniques and we’ll study detailed ‘real love’ examples.
I hope someone has learned something. Tomorrow we’ll attack the affiliate link cloaking material.