Home / Web Hosting / 2 Ways to Redirect Your Website

2 Ways to Redirect Your Website

Arrow redirect
Question: I want my website redirected to another site or page on my server. How do I setup automatic redirection?

Answer: There are many easy ways to redirect your website. Here are two commonly used methods.

1. .htaccess Redirect: Using an .htaccess file, you can instruct a visitor’s browser to any page on your website to look elsewhere for that page. This is useful because, in addition to redirecting the main page of your site, you can redirect any internal page to another.

In a previous post, we learned how to make error documents using .htaccess files. This uses the same principle but relies on the 301 Redirect code rather than a typical error code. It is quick and easy. Simply create an .htaccess file in the directory of the page you want to redirect. Then enter this on the first line:

Redirect 301 /oldpage.html http://www.example.com/newpage.html

If you want to redirect an entire site, enter this line:

Redirect 301 / http://www.example.com/

2. PHP: To redirect with PHP, you just need to enter the code on the very first line of your PHP page. This is useful if you had a php page that has moved. It will also work to redirect a default directory, if the php file is named index.php and no html index files exist. Just enter the following code:

< ?php
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
?>

There you have it, two easy ways to get your users to the right location without any interruption or clicking.

Check Also

servers

Importance of web hosting to business

The world of business is very ruthless and unfair in some cases. It is a …