Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this folder structure:


Today's my server is redirecting all requests of to and that's ok...

But I want to modify this behavior and keep acessing the /var/www/mysite/portal/ folder on background while still acessing the /var/www/mysite/abc/ folder as before.

That's what i've tried without sucess on my htaccess:

IndexIgnore *
Options +FollowSymlinks

<IfModule mod_rewrite.c>
    RewriteEngine On
    #This doesn't work!!!
    #RewriteCond %{REQUEST_URI} !^abc
    #Neither this :\
    #RewriteCond %{REQUEST_URI} !^/abc
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^$ /portal/index.php [L]
    RewriteRule . /portal/index.php [L]

All requests keep goin to when I use this .htaccess (with or without the commented lines)

share|improve this question
up vote 0 down vote accepted

I would use

Alias /abc /var/www/mysite/abc

although that doesn't go in an .htaccess file, it would need to be put in the VirtualHost configuration block.

If you don't have access to the virtual host configuration, try

RewriteRule ^/abc(.*) /var/www/mysite/abc$1

but make sure it goes before your existing rules.

EDIT: in response to your comment, maybe the simplest solution would be to do this:

DocumentRoot /var/www/mysite/
Alias / /var/www/mysite/portal/

But if that's not acceptable, one thing you could do is use AliasMatch:

AliasMatch ^/(abc|def|fgh|...)(.*)$ /var/www/mysite/$1$2

where of course the ... should be replaced with the rest of the names of your folders. But still, that requires you to type them all out once. There may be a way to automate it using RewriteRules and possibly subrequests, but I don't have the time to figure out what it would be and test it.

share|improve this answer
Ty for the answer but the problem is that I have dozens of folders to redict.. There's isn't a way to make it automatic? "Without folder or using a folder that doesn't exists: go here... With folder that exists: go there, in the folder" – TiuTalk Apr 13 '10 at 1:55
Ah, but you only asked about one of the folders. I'll see if I can come up with something. – David Z Apr 15 '10 at 1:02

You could try using the REQUEST_FILENAME conditions the other way around - i.e. say "if REQUEST_FILENAME exists (and is a file/directory/symlink), don't rewrite it" - something like

RewriteCond  %{REQUEST_FILENAME} -f    [OR]
RewriteCond  %{REQUEST_FILENAME} -d    [OR]
RewriteCond  %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [L]

That Rewrite rule means "let the request go through untouched", and the [L] flag should stop rewrite processing without hitting the portal rewrites below.

Other than that, I'd suggest using RewriteLog and RewriteLogLevel (at least level 3) to get more information about why the conditions aren't matching correctly.

share|improve this answer

Try adding this to your http config (Somewhere in the config, it doesn't work at htaccess or virtualhost level)

RewriteLog /tmp/rewrite.log
RewriteLogLevel 9

This will provide you with a line by line explaination of what it's trying to match against what regex, and what the final decision is.

Remove these lines afterwards, otherwise one day you'll discover you don't have nearly as much disk space as you thought you should...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.