htaccess folder and file exceptions do not work

Viewed 75

I have instrucions in htaccess to make all requests to go through index.php file. But it disables access to folders and files. So if I try to go to /uploads/products/thumbs/file.png it leads to index.php?lang=en&category=uploads&section=products (etc) instead of getting the file from the folder I added RewriteCond to add exception for existing files and folders, but it doesn't work for some reason.

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-z0-9_\-\.\(\)]+)?$ index.php?lang=en&category=$1&section=products [QSA,L]
RewriteRule ^([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)?$ index.php?lang=en&category=$1&category_lvl2=$2&section=products [QSA,L]
RewriteRule ^([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)?$ index.php?lang=en&category=$1&category_lvl2=$2&category_lvl3=$3&section=products [QSA,L]
1 Answers

Have your htaccess Rules file in following way. Please make sure to clear your browser cache before testing your URLs.

RewriteEngine On
RewriteBase /
##Conditions with rules for URL 3 levels of slashes here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)?$ index.php?lang=en&category=$1&category_lvl2=$2&category_lvl3=$3&section=products [QSA,L]

##Conditions with rules for URL 2 levels slashes here.       
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)?$ index.php?lang=en&category=$1&category_lvl2=$2&section=products [QSA,L]

##Conditions with rules for URL 1 level slash here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_\-\.\(\)]+)?$ index.php?lang=en&category=$1&section=products [QSA,L]
Related