301 redirect IP address to domain

Discussion in 'Apache' started by alicecatherine, Jun 30, 2012.

  1. #1
    Google has indexed my clients IP address rather than the domain, so now I'm messing with setting up a 301 redirect in my .htaccess file to redirect the IP address and all subsequent pages to the domain.

    I
    currently have something like this in place:


    RewriteCond %{HTTP_HOST} ^12\.34\.567\.890
    RewriteRule (.*) http://domain.com/$1 [R=301,L]

    I've used various redirect checker tools and keep getting the message: "... not redirecting to any URL or the redirect is NOT SEARCH ENGINE FRIENDLY" which leads me to believe the redirect isn't working.

    Am I doing something wrong or should I be trying a different method?

    Thanks!
    Alice


     
    alicecatherine, Jun 30, 2012 IP
  2. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    230
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #2
    Try with the following code:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^121\.121\.11\.121
    RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]
    Code (markup):
     
    RoseHosting, Jul 2, 2012 IP
  3. atxsurf

    atxsurf Peon

    Messages:
    2,394
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    0
    #3
    I think you should use
    Redirect permanent /(.*) hxxp://domain.com/$1
    for that. I am not sure if it is going to work with (.*) and $1 as i have only used it as
    Redirect permanent / hxxp://domain.com/
     
    atxsurf, Jul 2, 2012 IP