Forum Moderators: phranque

Message Too Old, No Replies

Three domains on one host: problem with urls

         

modorius

8:07 pm on Feb 11, 2011 (gmt 0)

10+ Year Member



I have 3 sites/domains sharing the same web space, each site in its own subdirectory on the web root. Like so:

wwwroot/domain1/
wwwroot/domain2/
wwwroot/domain3/

By default, all domains directed/connected to the root, and there is no way to change this by my host provider, unbelievably, so I have to use this setup in .htaccess for the root directory:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^[www.]*domain1.com$ [NC]
RewriteCond %{REQUEST_URI} !^/domain1/.*
RewriteRule ^(.*) /domain1/$1 [L]

RewriteCond %{HTTP_HOST} ^[www.]*domain2.com$ [NC]
RewriteCond %{REQUEST_URI} !^/domain2/.*
RewriteRule ^(.*) /domain2/$1 [L]

RewriteCond %{HTTP_HOST} ^[www.]*domain3.com$ [NC]
RewriteCond %{REQUEST_URI} !^/domain3/.*
RewriteRule ^(.*) /domain3/$1 [L]

This redirects domains to their subfolders/sites.

I also want to have extensionless urls, forced www and no index-files or trailing slashes on each site, so I use the following setup for each subdirectory/domain, example from domain1:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

# Force www
RewriteCond %{HTTP_HOST} ^(domain1\.fi)$ [NC]
RewriteRule ^(.*)$ [%1%{REQUEST_URI}...] [R=301,L]

# Redirect to remove /index.shtmlfiles.
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.shtml(\?.*)?\ [NC]
RewriteRule ^(.+/)?index\.shtml$ /%1 [NC,R=301,L]

# Redirect direct client request for old URL with .shtml extension
# to new extensionless URL if the .shtml file exists
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/\ ]+/)*[^.\ ]+\.shtml\ HTTP/
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(([^/]+/)*[^.]+)\.shtml$ [domain1.fi...] [R=301,L]

# Redirect any request for a URL with a trailing slash to extensionless URL
# without a trailing slash unless it is a request for an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ [domain1.fi...] [R=301,L]

# Internally rewrite extensionless URL request
# to .shtml file if the .shtml file exists
RewriteCond %{REQUEST_FILENAME}.shtml -f
RewriteRule ^(([^/]+/)*[^./]+)$ /$1.shtml [L]

All this works fine, except if I write "www.domain1.com/domain2" on the address bar, it leads to domain2-site, but the url won't change to "www.domain2.com". Also it is somehow possible to have "www.domain1.com/domain1" on the address bar also, while on domain1-site.

I want all the sites to appear separate to the user, there should be no possibility to have this kind of urls which indicate the opposite. How can this be achieved, what's wrong with my setup?

modorius

11:27 am on Feb 13, 2011 (gmt 0)

10+ Year Member



After few days of testing and reading forums and guides, I'm still way over my head. All the closely related topics and issues presented in this forum, have not offered a solution for my problem.

I still have many different urls for the same site:

www.domain1.com = www.domain1.com/domain1 = www.domain2.com/domain1 etc., when I should only have "www.domain1.com". And of course, same thing with domain2 and domain3.

Could some please shed some light on this, I have to admit I'm pretty lost here.

Thanks in advance.

jdMorgan

9:46 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is likely that you've got external redirects being executed after your internal domain-to-subdirectory rewrites. This will expose the subdirectory path to the client during the external client redirection.

Try using the [PT] flag on your domain-to-subdirectory internal rewrites. If that does not help, then you will either need to re-code each of the external redirect rules in the domain-subdirectories to strip out the current "domain-subdirectory path" before doing the external redirect, or you will need to move all of the external redirects to the main .htaccess file.

The end result that you must achieve is that regardless of location, all external redirects must execute before any internal rewrites can be executed in order to prevent internal filepaths from being exposed to clients as URL-paths during external redirects.

To prevent direct client access to your domain-subdirectories, you need a 'specially-constructed' redirect in your main .htaccess file in order to prevent infinite-looping:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(domain1|domain2|domain3)\.fi/[^\ ]*\ HTTP/
RewriteRule ^(domain1|domain2|domain3)\.fi/(.*)$ http://www.$1.fi/$2 [R=301,L]

Jim