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

Edited by Berre
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.