htaccess


Rewrite GET requests as virtual sub-folders in Apache

apache-logoIn search of a solution, to rewrite an one-parameter GET Request as virtual sub-folders, limiting it to specific values, I concluded to write the above Apache .htaccess rewrite rule.

This script, rewrite the value of the parameter named id, with the accepted values a,b or c as virtual sub-folders of a destination.

Script

RewriteEngine On
RewriteRule ^(a|b|c)\/?$ /?id=$1 [L]

Example

  • http://myhost.com/a/ rewrited as http://myhost.com/?id=a
  • http://myhost.com/a rewrited also as http://myhost.com/?id=a
  • http://myhost.com/d is not rewrited