Redirecting to another URL and passing the correct HTTP headers is extremely useful from SEO point of view if you migrate your website/blog from one URL to another. Other than redirecting to URL you can also use the redirect directive to send certain HTTP status codes when a page is accessed. The Redirect directive can be used in both the httpd.conf file as well as .htaccess file.
The syntax for Redirect directive is
Redirect [status] url-path url-to-be-redirected
this should be placed inside your .htaccess file or in the httpd.conf file inside the <Directory> directive. The [status] here is optional just using the following code will redirect visitors of your website to the new domain.
Redirect / http://new-domain.com
The status code sent is 302 which means moved temporarily
Redirect 301 moved permanently
By default the redirect directive sends a 302 status code but if you decide to permanently use your new domain you can definitely send a 301 moved permanently status code to your website. To do this use the permanent keyword
Redirect permanent / http://new-domain.com
Send a 404 or 410 error code
If for some reason you would like to send a 404 Not Found even for a page that existed you can do so by placing the 404 number in the redirect directive
Redirect 404 /a-directory
Note that after this change if you access this directory http://example.com/a-directory in Firefox you’ll see a blank page instead of your 404 error page but with Internet Explorer you’ll see the IE’s inbuilt 404 message.
The 410 gone code is used to tell that the page is permanently removed and there is no use of accessing it again. To send a 410 for a page
Redirect gone /location
In this way you can send any HTTP status code by following only one rule if the status code is between 300 and 399 the url-to-be-redirected parameter is mandatory else only the url-path needs to be specified. To check whether the correct status code is being returned use the HTTP Headers Lookup Tool
[…] header() is a PHP function using which we are sending a 301 “Permanently Moved” HTTP header with the home page in the “Location:” […]