Monday, January 15, 2018

How to Redirect a Domain

https://www.rosehosting.com/blog/how-to-redirect-a-domain

We’ll show you, how to redirect a domain. URL redirection, also
called URL forwarding, is a World Wide Web technique for making a web
page available under more than one URL address. When a web browser
attempts to open a URL that has been redirected, a page with a different
URL is opened. There are few ways to redirect a domain and it depends
on the web server used etc. In this tutorial we are going to show you,
how to redirect a domain with Apache web server and URL redirection with
NGINX web server.

Install Apache on your server if it is not installed yet.

On RPM based Linux distributions, like CentOS and Fedora, use the following command to install Apache:

yum install httpd

Verify that mod_rewrite module is enabled:

httpd -M | grep rewrite
rewrite_module (shared)

On Ubuntu and Debian, run:

sudo apt-get update
sudo apt-get install apache2

Activate the apache mod_rewrite module:

sudo a2enmod rewrite

Restart the Apache service:

sudo service apache2 restart

Create a simple virtual host in Apache

Create a simple virtual host in Apache for the old domain in which you redirect it to the new domain:
Use the Redirect Permanent directive to redirect the web client to the new URL:
ServerName old-domain.com
ServerAlias www.old-domain.com
RedirectPermanent / http://www.new-domain.com/
# optionally add an AccessLog directive here for logging the requests e.g. :
CustomLog ${APACHE_LOG_DIR}/access.log combined

Restart the Apache server:

Restart the Apache service to apply the changes.
You can also redirect a domain name to a different one using rewrite
rules placed in .htaccess file located in the document root directory of
the old domain name. Create a new .htaccess file and add the following
rules to it:

Restart NGINX

Do not forget to restart the nginx service for the changes to take effect:
service nginx restart
Of course you don’t have to redirect a domain if you use one of our managed VPS hosting services, in which case you can simply ask our expert Linux admins to redirect a domain name for you. They are available 24×7 and will take care of your request immediately.PS. If you
liked this post, on how to redirect a domain, please share it with your
friends on the social networks using the buttons on the left or simply
leave a reply below. Thanks.