The simplest URL rewrite ever?

This simple code snippet, if placed into an .htaccess file, would rewrite an alphanumerical “tail” of a URL into a variable accessible to an¬†index.php¬†residing in the same directory:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?tail=$1

For example, let’s say the the two files reside inside this directory:

Then, a user accessing this URL:

would see the output of this script:

Note that the “tail” must be alphanumerical (i.e., contain only letters and numbers).

Leave a Reply

Your email address will not be published. Required fields are marked *