July 2, 2013

htaccess rule cannot override previous rule

MrN’s Question:

I have a bunch of htaccess rule setup on website.

RewriteEngine On
RewriteBase /
RewriteRule ^google73947f9bfca52abe.html$    google73947f9bfca52abe.html [L]
RewriteRule ^page/(.*)$ index.php?title=page&r=$1 [L]
RewriteRule ^media/(.*)$ index.php?title=page&r=$1 [L]

RewriteRule ^admin/$    admin/php [L]
RewriteRule ^index.html$    index.php [L]
RewriteRule ^crons/$    crons/ [L]

#I did this to forward request to directory    
RewriteRule ^sites/$    sites/ [L]

#This  is the rule creating problem
#RewriteRule ^sites/([^.]+)$    sites/$1 [L]

RewriteRule ^([^.]+).html$   /index.php?title=$1
RewriteRule ^(.*).htm       index.php?action=$1 [L]RewriteRule ^([^.]+)$   /index.php?title=$1

I want to override every rule for those that start with site.com/sites to go the directory instead of going to index.php as it configured to do so.

Whenever I go to site.com/sites the sites takes me to site.com/site/?title=sites but I can still browse it as folder but Whenever I open a html file like lets say test.html it takes me directly to index.php on earlier directory as it is suppose to.

How to write rule which lets me browse a directly freely?

You have to configure to omit all the rules when the line sites is encountered.

Here is your solution:

RewriteEngine On
RewriteRule ^(sites) - [L]

#Rest of your rules

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!