Archive

Posts Tagged ‘domain’

domain redirect with mod_rewrite

January 16th, 2009 Comments off

There are at least two methods of an Internet address/domain to point to another location:

  • writing small frame and hosting it under originally address/domain – this way our original source will be hidden from visitors eyes.
  • writing small mod_rewrite rule to forward originally address/domain to another one, this is the case if we like both domain names, but think that the second one is more important.

Rules of modrewrite can be writen almost everywhere in apache configuration, but most convinient places are:

  • directory vhosts.d in apache configuration directory under etc, this location varies between Linux distributions but most likely it is something like /etc/apache2/vhosts.d/
  • file .htaccess that can be found at yours project directory served over apache, this can be something like /srv/www/www.niczsoft.com/.

In all locations You have to write the same content

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} www\.niczsoft\.com [NC]
RewriteRule . http://niczsoft.com/about/ [NC]
</IfModule>

With this rule I have asked my apache to answer all www.niczsoft.com requests with http://niczsoft.com/about/. Please take care for escaping dots in RewriteCond it is required as dot would be matched as any character. In the given example NC stands for no case, so www.NiczSoft.com and WwW.NICZSoft.CoM will match and return the requesting person to http://niczsoft.com/about/.