Forum Moderators: phranque

Message Too Old, No Replies

redirect from http://<host1>.<domainname> to http://<another-host>/myp

         

atul_iiit

3:55 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



Hi Apache Gurus,
I have gone through mod_rewrite documentation & read lot many other apache docs but believe me url rewrite is still mystery for me.

I want to redirect from ( with or without "/" )
[<myhost>.<domain>...]
[<myhost>.<domain>...]

to

[<anotherhost>.<domain>...]

Can some one help me out with rewrite condition for this

Regards
Atul

ChadSEO

6:00 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



Atul,

Are they hosted from within the same directory. If so, then you can only redirect traffic from a specific host by using:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule (.*) http://www.example.net/$1 [R=301,L]

This would redirect all traffic from www.example.com to www.example.net, and use the same page. So http://www.example.com/mypage.htm => http://www.example.net/mypage.htm. If www.example.com has it's own hosting space, then you don't need either of the RewriteCond's. If you want to redirect all traffic to a specific page, then use the following rule:

RewriteRule .* http://www.example.net/somepage.html [R=301,L]

And finally, if you only want to redirect traffic from http://www.example.com or http://www.example.com/, then use this one:

RewriteRule ^/?$ http://www.example.net/somepage.html [R=301,L]

Hopefully that should cover what you need.

Chad

atul_iiit

7:36 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



Hi ChadSEO,
Thanks a lot ,Last one was the one I was looking for
I was using below one

RewriteRule ^ http://www.example.net/somepage.html

Thats why It was redirecting to that URL but now Ur code works.

Can you please tell me what this stand for [R=301,L] & where can I get more information about R & L which u have given me so that I can read & update myself.

Regards
Atul

ChadSEO

7:44 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



Atul,

Using the "R" mean Redirect, rather than just doing a URL rewrite (serve up a different page without the user noticing). By default, R does a 302 redirect, or temporary redirect. Adding the "=301" does a 301 permanent redirect instead. I'm guessing you'll want to do a 301 for this, but there are several threads in this forum regarding 301 vs. 302. The "L" mean Last, basically don't process any more rules after this one.

For more reading on mod_rewrite, check out the apache documentation at [httpd.apache.org ]
There are also a couple of great threads by jd01, [webmasterworld.com...] and [webmasterworld.com...]

Chad

atul_iiit

8:09 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



Hi Chad,
That was really useful, I will go through documentation & these forum threads.

Regards
Atul