IBM HTTP Server redirection rules

IBM HTTP Server redirection rules are one of the most common task that every customer implement in order to redirect the URL to some specific content. In this blog entry I am just going to provide some links that I normally use for checking the redirection rules.

Basic information on mod_rewrite, http://httpd.apache.org/docs/current/mod/mod_rewrite.html

IBM HTTP Server specific rewrite rules, https://publib.boulder.ibm.com/httpserv/ihsdiag/rewrite.html

As part of information shared in rewrite rules,

Apache Module mod_rewrite module uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly. By default, mod_rewrite maps a URL to a filesystem path. However, it can also be used to redirect one URL to another URL, or to invoke an internal proxy fetch. It provides a flexible and powerful way to manipulate URLs using an unlimited number of rules. Each rule can have an unlimited number of attached rule conditions, to allow you to rewrite URL based on server variables, environment variables, HTTP headers, or time stamps.

mod_rewrite operates on the full URL path, including the path-info section. A rewrite rule can be invoked in httpd.conf or in .htaccess. The path generated by a rewrite rule can include a query string, or can lead to internal sub-processing, external request redirection, or internal proxy throughput.

Below are the attributes that are used in rewrite engine.

RewriteEngine
The RewriteEngine directive enables or disables the runtime rewriting engine. If it is set to off this module does no runtime processing at all.

RewriteBase
The RewriteBase directive specifies the URL prefix to be used for per-directory (htaccess) RewriteRule directives that substitute a relative path.

RewriteCond
The RewriteCond directive defines a rule condition. One or more RewriteCond can precede a RewriteRule directive. The following rule is then only used if both the current state of the URI matches its pattern, and if these conditions are met.

RewriteRule
The RewriteRule directive is the real rewriting workhorse. The directive can occur more than once, with each instance defining a single rewrite rule. The order in which these rules are defined is important – this is the order in which they will be applied at run-time.

RewriteMap
The RewriteMap directive defines a Rewriting Map which can be used inside rule substitution strings by the mapping-functions to insert/substitute fields through a key lookup. The source of this lookup can be of various types.

RewriteOptions
The RewriteOptions directive sets some special options for the current per-server or per-directory configuration.

 

A simple redirection rule is written below on how to forward a HTTP request to a HTTPS request. I have taken the content from IBM technote mentioned here.

RewriteEngine on
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

 

Basically we write N number of RewriteRules. I have seen customers using 4-5 files specifically to write rewrite rules and then they use the file as a reference in httpd.conf.