Forum Moderators: phranque

Message Too Old, No Replies

Rewrite IP to domain

e.g. 123.45.67.89 to ww*.example.com

         

bagatell

4:37 pm on Feb 23, 2004 (gmt 0)

10+ Year Member



I want to redirect links such as
ht*;//123.45.67.89/~example/file.htm to
ht*;//www.example.com/file.htm.
I've read the intro [webmasterworld.com]and a lot of threads and tried a number of rules but none have done the trick. So far I have
RewriteEngine on
RewriteRule ^http://123.45.67.89/~example/$1$ htt*://www.example.com/$1 [R=301 L]

Am I that simple or is mod_rewrite that complex? Help please.

jdMorgan

5:01 pm on Feb 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bagatell,

The hostname is not part of the URL-path as seen by RewriteRule. You'll need to use RewriteCond to test %{HTTP_HOST}, and then redirect pages requested on that hostname over to the correct domain:


RewriteCond %{HTTP_HOST} ^123\.45\.67\.89
RewriteRule (.*) http:www.exampl.com/$1 [R=301,L]

The "$1" in the substitution back-references the "page name" matched in the parenthesized pattern on the left. In this case, the ".*" pattern means "any number of any characters."

Jim

bagatell

5:28 pm on Feb 23, 2004 (gmt 0)

10+ Year Member



Thanks for that. This site is on a virtual host so I tried
RewriteCond %{HTTP_HOST} ^123\.45\.67\.89\~exampl 
RewriteRule (.*) http:www.exampl.com/$1 [R=301,L]

but nothing seems to have changed..

bagatell

5:30 pm on Feb 23, 2004 (gmt 0)

10+ Year Member



and
RewriteCond %{HTTP_HOST} ^123\.45\.67\.89\~exampl 
RewriteRule (.*) http:www.exampl.com/$ [R=301,L]

does nothing either

jdMorgan

5:39 pm on Feb 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Virtual hostnames are part of the URL...
This problem seems determined to drive you crazy finding the point of demarcation between hostnames and URL-paths, doesn't it? ;)

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

Jim

bagatell

4:30 pm on Mar 10, 2004 (gmt 0)

10+ Year Member



I have had an answer from my host on this.
It won't work on a shared IP. Anyone going to the shared IP will see CPanel's default page and never even get a chance to read the .htaccess file for that site.

So it's down to a carefully worked robots.txt to get Google to de-index the site and start again :(