I have been asked the question of how to do page redirects quite a lot recently, the simple answer is add a 301 page redirect using .htaccess, this is not the only way to do this but is probabily the simplest and method that will work on almost any Apache Linux hosting platform, if you are using the windows platform then you could do similar with your web.config file but I will write another tutorial on that.

What You need

  • plain text editor (notepad), I Like using notepadd++
  • FTP client to upload the .htaccess file

What Is A .htaccess File

.htaccess is a configuration file for use on web servers running the Apache (mostly found on Linux hosting).
When a .htaccess file is placed in a directory the Apache Web Server will detect the file and run the configuration within it, the .htaccess file are used to change the configuration of the Apache Web Server to enable or disable additional functionality and features that are available. Some of the features include page redirects, url rewriting, hotlink provention and even password protected directories.

Creating A Redirect

The first thing to do is create your .htaccess file as this is a hidden system file on linux and windows systems dont eaisly allow the creation of files that start with a "." cate a text file htaccess.txt, we will rename this once uploaded onto the server to .htaccess.

Once you have created the file you are now ready to start adding in the page redirects, there are a number of redirects that you can add but here I will show you a simple 301 redirect which is one of the most comon and ideal if you have moved a page to another location.

In you text file add the redirect lines, take note that you will need to adjust the pathes for your needs, not that comment are any lines that start with # and are ignored by the webserver it's always goot to add comments to section or redirects as you can have quite a few and it makes for simpler reading later on

# redirect old-page to new-page
RedirectMatch 301 /pages/old-page.php  /pages/new-page.php

after you have added the text save the file and then upload it to your document root of your hosting space, after the upload has completed rename the file to .htaccess, if the file is nolonger viewable then you may need to change the settings on your FTP client to show hidden files.

Examples Of Other Redirects

Redirect index.html to a subfolder:

# This allows you to redirect index.html to a specific subfolder
Redirect /index.html /subfolder/

Redirect and set index page order:

# set index page order
DirectoryIndex index.html index.php

Redirect your entire site to another domain you can do this as a 301 permanent or a 302 temporary redirect. Doing a 302 can be useful for SEO reasons when you want a temporary page and plan to switch back to your main site at another date.

# 301 permanent redirect entire website
Redirect 301 / http://other-site.co.uk/
# 302 temporary redirect entire website
Redirect 302 / http://other-site.co.uk/

Add a comment

0.0(0 votes)

Next Post Previous Post