25.2. mod_rewrite

You will probably find mod_rewrite already installed by your ISP on your web server. This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule to provide a really flexible and powerful URL manipulation mechanism. The URL manipulations can depend on various tests, for instance server variables, environment variables, HTTP headers, time stamps and even external database lookups in various formats can be used to achieve a really granular URL matching (see the Apache Documentation of mod_rewrite).

Caution Find out if you have mod_rewrite installed first!

There is little meaning in trying to implement an URL manipulation solution, if your ISP has not installed mod_rewrite on your web server - so you better find out before you start. The easiest way is to call your ISP and ask. If this appears to be more time consuming than you thought, you can also find it out yourself if you save the following 3-liner


in a file called test.php, then upload it to you web server and open it with your browser. It will display a wealth of information about your PHP configuration (that's why you should delete it, or at least restrict access to it by putting it in a .htaccess password protected directory, when you are done). Among others, you will see a section called "apache". Search for "mod_rewrite" in the "Loaded Modules" part. If you find it, mod_rewrite is up and running on your web server.

Figure 25-1. Apache section of the phpinfo() output: mod_rewrite is loaded.

Apache section of the phpinfo() output: mod_rewrite is loaded.

The internal processing of this module is very complex but needs to be explained once even to the average user to avoid common mistakes and to let you exploit its full functionality. For this we use the Apache Documentation of mod_rewrite. Of course, there is little point in reproducing it here in whole, so you are referred to it for all the gory details.

Here we will cover:

Help us make a better PHP-Nuke HOWTO!

Want to contribute to this HOWTO? Have a suggestion or a solution to a problem that was not treated here? Post your comments on my PHP-Nuke Forum!

Chris Karakas, Maintainer PHP-Nuke HOWTO


Site Info v2.2.2

Last SeenLast Seen
Server TrafficServer Traffic
  • Total: 373,249,588
  • Today: 57,764
Server InfoServer Info
  • Dec 13, 2018
  • 02:56 pm CET