Apache mod_rewrite any domain to my domain help pls

Discussion in 'Server Operation' started by luciogodoy, Sep 7, 2013.

  1. luciogodoy

    luciogodoy New Member

    Hi all

    I'm setting a hotspot service and I would like that when a user types any domain name on their browser it redirects to my server domain name.

    I have achieved part of it, configured bind dns to resolve all domains to the web servers IP address, but it redirects as the domain they have tried to access, so for instance:

    When the user types www.google.com it resolves to my servers IP address however apache displays my webpage with googles domain name on the location bar.

    I have tried this code which works for google.com and google.co.uk, but its quite messy if you want to do it for all domain names and also I need to exclude my own domain from it otherwise i get too many redirection errors.

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

    I have a Centos 6 server with apache 2.2.16 installed


  2. fbartels

    fbartels New Member

    Hi Lucio,

    this one acts as a kind of "catch-all":

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

Share This Page