Forum Moderators: phranque
However, I have one 'web space' (for the sake of clarity here I'll call this 'root') and the hosts point all of my domains at this directory, although I can manage which specific directory under 'root' using an online config tool.
In essence I have the following:
maindomain.co.uk points to /root
otherdomain.co.uk points to /root/dir1
anothersite.com points to /root/dir2
This is fine up to a point as a visitor wanting to go to anothersite.com/page.php goes there, but unfortunately they can also see that page by going to maindomain.co.uk/dir2/page.php although probably with broken css and image links.
Conversely, Google is showing images on the sites using the maindomain path (and is also indexing documents in the other doamins using full paths from 'root')
What I therefore need to do is intercept any requests from these directories and redirect them to the appropriate domain address eg
/root/dir1 to otherdomain.co.uk
/root/dir2 to anothersite.com
I know I can use rewrites in the .htaccess file OK as it's currently setup witha simple 'add the www prefix' rule so:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^maindomain.co.uk
RewriteRule (.*) http://www.maindomain.co.uk/$1 [R=301,L]
I'm think that somthing like the following should work but I'm keen to get other peoples input before commiting anything to the server.
RewriteRule ^dir1(.*) http://otherdomain.co.uk/$1 [R]
RewriteRule ^dir2(.*) http://anothersite.com/$1 [R]
If the above look OK, can I just add them 'as is' to .htaccess or do I need to adjust the existing rules?
Many thanks folks,
Mik F
[edited by: jdMorgan at 7:52 pm (utc) on Feb. 28, 2006]
[edit reason] De-linked [/edit]
I think you'll find, if you test this concept using a "test domain", that it will create a loop.
Domains are currently rewritten or aliased to subdirectories, and now you're adding code to redirect them back unconditionally.
One solution is to use the server variable %{THE_REQUEST}, so that only client requests will be redirected; internal rewrites will be unaffected:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /dir1/
RewriteRule ^dir1/(.*) http://otherdomain.co.uk/$1 [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /dir2/
RewriteRule ^dir2/(.*) http://anothersite.com/$1 [R=301,L]
GET /dir1/mypage.html HTTP/1.1
Jim