Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess redirect all requestes to index.php except sub folder

I have a CMS installed at the root of my domain with the following htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

This takes care of friendly urls to redirect everything to index.php. My problem is that I have a sub-folder which has another cms. I need the requests to the sub-folder be redirected to the proper folder instead index.php.

I tried the following but it doesn't seem to work

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(sub-folder)
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Can anyone help?

Thanks

like image 732
jribeiro Avatar asked Dec 20 '12 01:12

jribeiro


1 Answers

You should verify properly if request uri match the sub folder

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/subfolder
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

In any case, the first two rewritecond means: if request file name is not a file or a directory. Which means that if the file you are referencing is into the sub folder and the sub folder is into your docroot, you don't need to do anything.

If still won't work, enabling the log could help you:

RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

avoid this log in production

Using a high value for Level will slow down your Apache server dramatically! Use the rewriting logfile at a Level greater than 2 only for debugging!

like image 55
freedev Avatar answered Oct 21 '22 20:10

freedev