Webmasters are often faced with a situation where one or more files have names that are misfits for the very purpose of the file. You may also feel like there is a need to rename the entire file tree all at once. If that is the case, you will be pleased to know that it is easy to change links in your own site. However, it is a much more tedious process if you want to change the external links to some other site.
Why redirecting is preferable over changing locations?
Redirect using PHP
If it is a conditional loop, you can redirect your visitor to another page by simply using the following code:
<?php header('Location: mypage.php'); ?>
Note that in order for a php to work your page format should be in .php
Please note that in this method, mypage.php is the page address to which you would like to send your visitors. The address could be absolute and may include parameters in the format:
For absolute/relative paths
When toying with absolute or relative paths, it is highly recommended to choose an absolute path straight from the server root (DOCUMENT_ROOT). You will simply need to follow this format:
<?php header('Location: /directory/mypage.php'); ?>
In case the target page is hosted on another server you will need to include the complete URL:
<?php header('Location: http://www.ccm.net/forum/'); ?>
Redirecting with HTML
Redirect with HTML is more of a meta redirection code. It is more of a redirect from the client’s end. Nevertheless, it is never a permanent 301 redirect for a page rank transfer in any case. The meta refresh on HTML has a transfer time of flat 0 seconds. It is automatically considered by Google as an indication for a 301-page rank transfer or redirects.
In case, you are looking to solve the permanent 301 redirect, it can be done with the PHP redirect method mentioned above.
Like PHP, the redirection is conducted using by varying the meta refresh in the head section of the page. There is a second insertion of the link in the body section for revisiting purpose. You can use this code:
<!DOCTYPE html> <html> <head> <!-- HTML meta refresh URL redirection --> <meta http-equiv="refresh" content="0; url=http://www.mydomain.com/new-page.html"> </head> <body> <p>The page has moved to: <a href="http://www.mydomain.com/new-page.html">this page</a></p> </body> </html>
HTML Redirect using Timer
You can also redirect with a timer or redirect by using a specific time you want. Example: You want to redirect or refresh the page on a specific amount of seconds.
This example will redirect page to new-page.html after 5 seconds.
<!DOCTYPE html> <html> <head> <!-- HTML meta refresh URL redirection --> <meta http-equiv="refresh" content="5; url=http://www.mydomain.com/new-page.html"> </head> <body> <p>The page has moved to: <a href="http://www.mydomain.com/new-page.html">this page</a></p> </body> </html>
Redirect using .htaccess
It is fairly simple to redirect to a page by using .htaccess. All you need to do is:
- Make an empty file using one of the text editors and name the file as htaccess.txt.
- Edit the text in the file.
(Permanent) 301 Redirect: In this way, you can point the whole site to another address permanently. This is a common redirect method that can be used in most of the situations. Here’s the code:
Redirect 301 /http://example.com/
(Temporary) 302 redirect: The entire site gets redirected to a temporary new location. This is great if you have SEO on the mind and are going to send the page to a new landing page. In this manner, you can switch back to the original page anytime you want.
Redirect using a WordPress plugins
This is by far the simplest way to manage a redirect if you are running a WordPress site. Here are two simple plugins that can do the job for you.
This is the simplest way to introduce and manage your redirects on a WordPress website. All you need to do is install the plugin and activate it. Once the plugin is activated, go to the Tools and then Redirection so that your redirects are set up.
- Page Links To
This is another extremely simple plugin that allows you to retain a current page and then link it to another page or post. All you need to do is install and activate the plugin, roll down to the bottom of a page and check the “Page Links To” box. Enter the landing page of your choice.