Well we can control how the server serves stuff to clients by defining rewrite rules.
As servers are dumb, its important to explain well about the rewrite rules. For example you should explicity say when a rule matches a URL pattern, no need to seek for further rules('L' flag).
The most interesting part is the regular expressions used for rewrite rules. This I will discuss sometime later...But to do some hit and try use me. Okie, first with apache: The rewrite rules are handled by module mod_rewrite. This reads the rewrite conf file configured in httpd.conf.
Include the rewrite rule path in httpd.conf >> VirtualHost >> Include /path/to/rewrite.conf
Define a rewrite rule file /path/to/rewrite.conf All set. Ok now the details on rewrite rules:
#This says that rewrite engine is on. This can be configured in httpd.conf as well. RewriteEngine On
#for debugging only RewriteLog logs/rewrite.log RewriteLogLevel 9
#check if a condition is true: RewriteCond %{HTTP_HOST} ^local.xyz.com$
#if true above then only apply the below rule(s). RewriteRule ^/?$ /journal/index.html [PT]
#RewriteRule has the syntax RewriteRule PatternSubstitution [flags]
The important flags are:
L - Stop the rewriting process here and don't apply any more rewriting rules R - Redirect. Must have 'L' flag usually with this(to stop processing further) N - Re-run the rewriting process P -This flag forces the substitution part to be internally forced as a proxy request and immediately NC - No case .This makes the Pattern case-insensitive PT - pass through to next handler . Works with alias..Used rarely??.
Lots more on Configuration Directives for apache rewrite rules go here:
Gotcha : To apply a rewrite rule based on the request parameter you *have* to use RewriteCond %{QUERY_STRING} ^param=value By default the RewriteRule does not apply for request parameter On ISAPI rewrite rules for IIS:
Though it is supposed to be a clone of apache mod_rewrite to help IIS do the redirections there are some differences. There are more ISAPI_Rewrite directives for IIS like RewriteHeader ,etc More or less the syntax match (thank god) and should be easy if u know apache rewrites. More on IIS rewrite rules here