logos

With Andrii Grytsenko


Technical Diary - With Andrii Grytsenko

Make redirection from one web site to another via htaccess

Here is some example how to redirect web users from one domain to another one.

In the event of you have 2 domains and you want to use one of this as general one. And redirect all requests from one domain to another one. For example redirect requests from test.com.ua to test.com you need to install apache with mod_rewrite module. For debian you have to make next command(as root):

#cd /etc/apache2/mods-enabled
# ln -s ../mods-available/rewrite.load  rewrite.load

For another distros you able to compile apache from sources with option “–enable-module=rewrite”.

Also you should put or change some lines in the apache configuration file (apache2.conf OR httpd.conf). In main section:

AccessFileName .htaccess

In the Directory section :

Options Indexes FollowSymLinks MultiViews
AllowOverride All

After that restart apache server:

# /etc/init.d/apache2 restart

Now you are ready to make your .htaccess file. Go to the your web directory:

# cd /var/www/
# cat > .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test\.com\.ua$
RewriteRule (.*) http://test.ua/$1 [L,R]

Check your web site via browser. If you have done everything describe above in proper way you will be redirected from test.com.ua to test.ua.

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Categories

Translate