So I set this blog up to use permalinks and it automatically gave me the content for my .htaccess file to use mod_rewrite to handle the links. That was pretty cool. This reminded me of a site I recently worked on that I ended up using mod_rewrite to hide all the ? and & symbols in the URL. One of the things that I was unsure of was how to create an exception to the rule like for example css files that didn’t need to be redirected. The answer was RewriteCond. Here’s an example of what I used in my Apache config:

<IfModule mod_rewrite.c>
          RewriteEngine on
          # Exclude css directory from rewrite
          RewriteCond %{REQUEST_URI} !^/css
          # Print out "static" pages
          RewriteRule /([a-z]+).htm /site.cgi?page=$1

Of course, the site.cgi script handles whether or not the file exists locally, to prevent remote page calls that can compromise your server very quickly. :)

Leave a comment

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