-1

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

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

Patrick Mevzek
  • 10,581
  • 7
  • 35
  • 45
Matt
  • 43

1 Answers1

0

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.

nalply
  • 1,147