In this post we will be learning about redirects. And see how you can redirect your web-page.
We will see two ways to redirect web-pages:
- Through your registrars’ Cpanel.
- Right into your code.
Through cPanel redirect feature
You can easily redirect your visitors from one page to another with the help of the Redirects feature.
To setup a redirection, access your website’s Control Panel and locate the Redirects menu.
In the Create a Redirect section. You can set up a redirection from one page of your website to another. This also works for subdomains or completely different websites.
If you choose to use HTTPS, make sure the redirected page has a certificate first, because redirecting to a website without an SSL certificate but using the HTTPS protocol for it, will most likely land your visitor to an error page
Now let’s see how you can set redirection by including few lines in your code.
The simplest way to redirect to another URL is with the Meta Refresh tag. We can place this meta tag inside the
<head> at the top of any HTML page like this:
<meta http-equiv="refresh" content="0; URL='http://new-website.com'" />
locationproperty on the
// Use any of the following lines below.
window.location = "http://new-website.com";
window.location.href = "http://new-website.com";
The most common method of redirecting a web page is through adding specific rules to a
.htaccess file on an Apache web server.
Redirect 301 / http://www.new-website.com
With PHP we can use the header function, which is quite straightforward:
header('Location: http://www.new-website.com/', true, 301); // Permanent redirection.
#header('Location: http://www.new-website.com/', true, 307); // Temporary redirection.
This is it for this post. Now the comment section is all yours.