How to redirect http://123.123.123.123 to http://www.domain.com using 301 redirect?

Discussion in 'Install/Configuration' started by phallstrom, May 8, 2007.

  1. phallstrom

    phallstrom New Member

    Hi -

    I have a need to redirect requests made directly to the IP address of our server back to the official domain name of the server using a 301 redirect, but I'm not sure how to proceed. I've redirected other "vanity" domains easily, but this seems different.

    The problem is that GoogleBot for some reason accesses our server by IP directly, without specifying the Host: header and is counting it as two separate pages in it's database (which is a problem).

    So, I want any request made directly to the IP address without a Host: header to get redirected...

    To complicate things however, the server is part of a farm so I don't want it's individual hostname to be redirected, just if it's made to the IP.

    Is this possible?
  2. mistwang

    mistwang LiteSpeed Staff

    Using a rewrite rule is the simpliest solution.
  3. phallstrom

    phallstrom New Member

    Ah. duh. Almost there... I have this:

    RewriteCond %{HTTP_HOST} !^(www|host)\.domain\.com [NC]
    RewriteRule ^/(.*) http://www.domain.com/$1 [L,R=301]

    What I would like is to abstract "host" out of it by using %{ENV:HOSTNAME}, but it doesn't seem to take. I've tried tacking on a variety of ENV vars for the rewrite to see if any of them are available, but no luck.

    Is the %{ENV:variable} construct not available in litespeed? (this is 3.0).

    Thanks!
  4. mistwang

    mistwang LiteSpeed Staff

    %{ENV:variable} is available but %{ENV:HOSTNAME} is not, it has to be set explicitly. And you cannot use it in the matching pattern.

Share This Page