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:

http://mysite.com/myDir/

Then, a user accessing this URL:

http://mysite.com/myDir/ABC123xyz

would see the output of this script:

http://mysite.com/myDir/index.php?tail=ABC123xyz

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 *