Sunday, January 23, 2011

Rewrite all url in a subdirectory to a specific page

I need an .htaccess placed in example.com/mydir/ that rewrite (without redirect) all url in /mydir/(.*) to /mydir/index.php?var=$1. If an url is to an exist path or file it's not relevant for me (it must be rewrite).

I can't use +FollowSymLinks, but SymLinksIfOwnerMatch.

Thanks.

  • I think you're looking for something like this:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/index.php
    RewriteRule (.*) index.php?var=$1
    

    First two RewriteCond's check to make sure the file or directory do not exist. Third checks to make sure you are not looping. It may need to be tweaked based on your server settings, but it should get you going.

0 comments:

Post a Comment