Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have multiple domains setup with my webspace (all via a hosting provider)

So www.maindomain.com links to /maindomain on my webspace. www.domain2.com 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 www.maindomain.com/test but www.maindomain.com/domain2/test. 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 stackoverflow.com 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
add comment

1 Answer

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 www.maindomain.com/test. 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 maindomain.com/test it automatically redirects to maindomain.com/maindomain/test and works! When commenting out the lines above maindomain.com/test 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 maindomain.com/test 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
add comment

Your Answer

 
discard

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.