tags:

views:

36

answers:

1

How can I use URL rewriting in .htaccess to redirect to different domains depending on the URL?

Examples:

  • http://ONE/ to http://TWO/
  • http://ONE/some_content to http://THREE/some_content
+2  A: 

This ought to work if you want to redirect the client:

# http://ONE/ to http://TWO/
RewriteCond %{HTTP_HOST}    =one
RewriteRule ^$             http://two/ [R,L]

# http://ONE/some_content to http://THREE/some_content
RewriteCond %{HTTP_HOST}    =one
RewriteRule ^(.+)$         http://three/$1 [R,L]

If you prefer to proxy the requests, change the R flag to a P instead.

Martin
Thank you for your help, unfortunately it doesn't work.The first case does not change the domain ONE in TWOThe second case brings a 404 error on the domain ONEHere is my complete .htaccessOptions +FollowSymLinksRewriteEngine OnRewriteBase /RewriteCond %{HTTP_HOST} =ONERewriteRule ^/$ http://TWO/ [R,L]RewriteCond %{HTTP_HOST} =ONERewriteRule ^/(.+)$ http://THREE/$1 [R,L]Is it something wrong ?
Sinklar
Sorry, I should have used an answer instead of a comment...
Sinklar
Sorry, I missed the htaccess part. You'll need to remove the initial slash from the RewriteRules, i.e. `^/` becomes only `^`I edited my answer to reflect this.
Martin
Woaw, thank you very much.It's working now. I'm really happy. :-)
Sinklar