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 multiple domains setup with my webspace (all via a hosting provider)

So links to /maindomain on my webspace. links to /domain2 on my webspace. Pretty simple so far.

However as soon as I place another folder into one of those directories the folder of the domain itself gets mentioned in the URL again.

So imagine this … I have a folder test inside maindomain. In that case the URL to this folder is not but So the maindomain directory name that is repeated in the url.

Why is that? Is there a way to make that go away via mod_rewrite and .htaccess?

I found this in the .htaccess file on the root of my

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/maindomain/
RewriteCond %{DOCUMENT_ROOT}/maindomain%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/maindomain%{REQUEST_URI} -d
RewriteRule ^(.*)$ /maindomain/$1 [L]

However, since I'm not much of a server-guru I can't figure out what that actually means. Can someone please help me out here?

share|improve this question

migrated from Oct 15 '12 at 19:07

This question came from our site for professional and enthusiast programmers.

Did you post the complete .htaccess file? There might be other directives and if I don't see them I might give you wrong counsel. – nalply Oct 13 '12 at 14:44
Well, this is all! See my comment in your answer underneath! Without those lines the urls wouldn't work. I just want /maindomain/ not shown in my address. – Matt Oct 14 '12 at 8:12

The first RewriteCond checks whether the uri does NOT start with /maindomain/.

The second and the third check the existense of the file as a normal file OR as a directory.

Then if all conditions are fulfilled, rewrite in prepending /maindomain/ to the already existing URL.

Now to your problem. You have the directory {DOCUMENT_ROOT}/maindomain/test/ and want it to be reachable from This additional lines does the work. Insert it just below RewriteEngine On:

RewriteRule ^test/(.*)$ /maindomain/test/$1 [L]

This takes any URI starting with /test/ and redirects it to /maindomain/test. The [L] part means, stop this round of redirecting here (and don't evaluate the four lines below) and start a new round.

Attention: this is not tested (since I don't have access to your system). URL Rewriting often needs some testing to get it right. StackOverflow is not the right medium to give you support. You need to learn URL Rewriting yourself or hire someone who knows it.

share|improve this answer
Well, I see! Without those lines mentioned above the desired url I want doesn't work at all. Right now when calling it automatically redirects to and works! When commenting out the lines above leads to a 404. So the lines above are needed for it to work. However I wonder if I can add an additional rule that "hides" the /maindomain/ directory from the url so that the called url stays like this in the address bar and WORKS. – Matt Oct 14 '12 at 8:11
Thank you for your update! However, this doesn't work for me. Moreover is there no way of defining a "variable" for test so I don't have to define a seperate rule for every subdirectory? – Matt Oct 14 '12 at 17:04
As I have said, this needs some testing. You are on your own now. I flagged this question as too localized already because your question won't help anybody else. – nalply Oct 14 '12 at 17:07

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.