Jump to content

Rewrite only if first part is not an existing directory


Berre

Recommended Posts

My root directory (in the actual file system) has several subdirectories, one of which is a "main" site, while the others are individual user sites. Every subdirectory has their own .htaccess file, but it's the root .htaccess file that is the topic. I have tried to create rewrite rules myself, but I can't get the rewrite conditions to properly check for the folder existing.

 

/main/lots-of-files

/homer/lots-of-files

/marge/lots-of-files

/bart/lots-of-files

/lisa/lots-of-files

/maggie/lots-of-files

/.htaccess

 

So this is the root of my web server. When I go to sites.example.com I see the directory listing above. I want sites.example.com to point to "/main/" instead of "/". Not only that, but I want everything not specifically pointing to any user dubdirectory to rewrite to /main/.

 

These should not rewrite to /main/, because these directories exists in root*:

/homer/index.php

/marge

/lisa/pictures/profile.gif

 

* The files may not exist in those positions, as /homer/, /marge/, /bart/, /lisa/ and /maggie/ all has a .htaccess file with their own rewrite rules.

 

These should rewrite to /main/:

/

/philip

/bender/bending/rodriguez.php

/basically/anything-not-existing-as-a-directory

/some-file.txt

Maybe these would be useful in your htaccess



#If the request is not an actual existing file
RewriteCond %{REQUEST_FILENAME} !-f

#If the request is not an actual existing directory
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule //Your rewrite rule

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.