How to redirect a domain name using .htaccess

If your domain name is changed for some reason and you want users/search engines to redirect to new Location then add the below code in .htaccess file of your website.

Example:

If you want to redirect http://olddomain.com to http://www.newdomain.com

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ http://www.newdomain.com%{REQUEST_URI} [R=301,L]
</IfModule>

After you add above code in .htaccess file it will as also redirect links.
Example:

http://olddomain.com/archive/2019 will redirect to http://www.newdomain.com/archive/2019

How to Hide Apache Version from HTTP Header

You can check the HTTP header of your server by using a simple curl command.
In HTTP header you will see on what version Apache is running.

$ curl -I  http://justgeek.in

You can see that your server is running with Apache 2.4.18 server.

 HTTP/1.1 200 OK
 Date: Mon, 2 December 2019 11:36:14 GMT
 Server: Apache/2.4.6 (CentOS)
 Last-Modified: Thu, 20 Oct 2016 05:30:08 GMT
 Accept-Ranges: bytes
 Content-Length: 11321
 Vary: Accept-Encoding
 Content-Type: text/html

To hide Apache Version, you will have to edit your Apache configuration file and add following variables.
Restart your apache after making change.

ServerTokens Prod
ServerSignature Off

Use the same http command again to check HTTP Header

$ curl -I  http://justgeek.in

Now you can see that header is only showing that Apache is running, but no version or OS details available there.

 HTTP/1.1 200 OK
 Date: Mon, 2 December 2019 11:36:14 GMT
 Server: Apache
 Last-Modified: Thu, 20 Oct 2016 05:30:08 GMT
 Accept-Ranges: bytes
 Content-Length: 11321
 Vary: Accept-Encoding
 Content-Type: text/html