I have this folder structure:


Today's my server is redirecting all requests of www.mydomain.com to www.mydomain.com/portal and that's ok...

But I want to modify this behavior and keep www.mydomain.com acessing the /var/www/mysite/portal/ folder on background while www.mydomain.com/abc/ 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 www.mydomain.com/portal/ when I use this .htaccess (with or without the commented lines)


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.

  • 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" – Thiago Belem 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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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