Search code examples
apache.htaccessurl-rewriting

htaccess ignore directory and subdirectories of existing folder


I have the following structure

- .htaccess
- cms
- other_cms
-- xyz

In the .htaccess I have a lot of rewrite rules which I want to ignore for /other_cms.

I added the following on top of my .htaccess

RewriteEngine On
RewriteRule ^other_cms/ - [L]
RewriteRule ^other_cms/test/ - [L]
RewriteRule ^other_cms(/.*)?$ - [L,NC]
    
RewriteCond %{REQUEST_URI} ^other_cms/(.*)$
RewriteRule ^.*$ - [L]

My goal is that every subdirectory of /other_cms (no matter if it really exists or not) and /other_cms itself is ignored by this .htaccess file in the root.

I also tried to add a condition to every rule:

RewriteCond %{REQUEST_URI} !^other_cms(/.*|)$

When I open /other_cms/test it still calls all rules and the 404 of the /cms is applied.

I have added an .htaccess file to /other_cms including RewriteEngine Off but I suppose this is never read.

What am I doing wrong?


Solution

  • I solved it using the following on top in the root .htaccess file:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^other_cms/(.+)$ /other_cms/index.html?u=$1 [NC,QSA,L]
    

    and I removed the .htaccess file in the other_cms/ folder.

    This makes sure it uses the index.html file of my subfolder.