Sunday, June 3, 2012

.htaccess mod_rewrite - how to exclude directory from rewrite rule


I have 8 lines of rewrite rules in my .htaccess file. I need to exclude two physical directories on my server from these rules, so they can become accessible. For now all requests are sent to index.php file.



Directories to exclude: "admin" and "user".



So http requests: http://www.domain.com/admin/ should not be passed to index.php file.




ErrorDocument 404 /index.php?mod=error404

Options FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

RewriteRule ^([^/] )/([^/] )\.html$ index.php?lang=$1&mod=$2 [L]
RewriteRule ^([^/] )/$ index.php?lang=$1&mod=home [L]



Thanks for any advise!


Source: Tips4all

2 comments:

  1. Try this rule before your other rules:

    RewriteRule ^(admin|user)($|/) - [L]


    This will end the rewriting process.

    ReplyDelete
  2. add a condition to check for the admin directory, something like:

    RewriteCond %{REQUEST_URI} !^/?(admin|user)/
    RewriteRule ^([^/] )/([^/] )\.html$ index.php?lang=$1&mod=$2 [L]

    RewriteCond %{REQUEST_URI} !^/?(admin|user)/
    RewriteRule ^([^/] )/$ index.php?lang=$1&mod=home [L]

    ReplyDelete