views:

36

answers:

1

I have two domains that point to the same root folder of my webspace. My root directory is setup like so:

  • /domain1
  • /domain2
  • /shared

Where requests to...

Current .htaccess:

# Redirect domain1.com paths to domain1 folder.
RewriteCond %{HTTP_HOST} ^www\.domain1\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/domain1/
RewriteRule ^(.*)$ /domain1/$1

# Redirect controllers to index.php.
RewriteCond %{HTTP_HOST} ^www\.domain1\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^domain1/(.*)$ /domain1/index.php?controller=$1 [QSA,L]

# Redirect domain2.com paths to domain2 folder.
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/domain2/
RewriteRule ^(.*)$ /domain2/$1

# Redirect controllers to index.php.
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^domain2/(.*)$ /domain2/index.php?controller=$1 [QSA,L]

What's remaining to do is:

  1. Don't serve pages from http://www.domain1.com/domain1 if the user types this in manually.
  2. Don't serve pages from http://www.domain1.com/domain2 if the user types this in manually (I've already implemented this but omitted it for brevity).

Note: I would rather not use symlinks since I run xampp on windows for local development.

My question is:

How can I redirect internally from http://www.domain1.com to http://www.domain1.com/domain1 but not serve http://www.domain1.com/domain1 if it is typed in by the user?

+1  A: 

You need to test the request line to see what URI has originally been requested:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(domain1|domain2)[/?\ ]
RewriteRule ^(domain1|domain2)($|/) -

In this case you can send the status code 404 ([R=404] flag, since Apache 2) or rewrite the request to some point where such requests are handled.

Gumbo
Hey thanks,I'll try this out tonight and see how it goes :)
Chris MacDonald
THE_REQUEST works like a charm! Thanks Gumbo.
Chris MacDonald