htaccess redirect all requestes to index.php except sub folder

12,355

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!

Share:
12,355
jribeiro
Author by

jribeiro

Full Stack Web Developer driven by passion, innovation and creativity! I specialise in creating great web and mobile experiences for companies and creatives

Updated on June 05, 2022

Comments

  • jribeiro
    jribeiro almost 2 years

    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