upwithabang web designer resources

Donation? Yes, it is better than ads and it's optional. If this site has helped you please consider remunerating an amount you deem appropriate.


del.icio.us icon

Redirecting browsers to a different web page using .htaccess

To summarize, add this to your .htaccess file:
    Redirect 301 file.html http://www.mydomain.com/newfile.html

Sometimes you want to re-organize your web site. In my case I decided to move articles to a new 'articles' folder. So what happens to all the links pointing to the old location? I needed to redirect them. The procedure I will discuss here only works for Apache web servers. You are probably using Apache but if not you are probably using a Microsoft web server (IIS). If so, do a web search on keywords like "iss redirect".

Originally I had an HTML file as so:
    http://upwithabang.com/divs-article.html
I decided I wanted all my articles in an 'articles' folder, plus this article I wanted to rename. So in the end, this article was replaced with:     http://upwithabang.com/articles/css-divs-instead-of-tables.html
The next step was to change all the links on my site to the replacement article.

But what about links from other sites?
Other sites may link to that web page including search engines and search engine robots and spiders. The next thing to do is to use a special file to tell other sites that the article has moved. This file is called .htaccess. This file does much more than just redirects so you may already have this file on your server. You may have one in every directory of your server. It is best to check so you don't overwrite anything in it that may be important. I'll write through the step-by-step procedure I used for my file to show you what to do.

  1. Log onto FTP site and go to the directory containing the original file (divs-article.html)
  2. Look at the directory file and check if .htaccess exists, if it does, download it
  3. If the directory doesn't already have an .htaccess file go to step 5
  4. Open the .htaccess file and move to the bottom of the file so that you don't change anything in it
  5. Add the follow line to .htaccess:
    Redirect 301 /divs-article.html http://upwithabang.com/articles/css-divs-instead-of-tables.html

  6. Save the .htaccess file and upload it to the directory that contains the original file (divs-article.html)
  7. Optionally, the original file can be deleted
  8. Test on live web site

301 tells browsers, robots and spiders that the page has moved permanently. If for some reason you are moving the page temporarily you can use 302.

/divs-article.html the path to the original file is relative to the directory holding the .htaccess file. Since we are editing the .htaccess file in the same directory as the original file, the source path looks like this.

http://upwithabang.com/articles/css-divs-instead-of-tables.html is the new file location. It should be the full absolute path beginning with http. If not, it must begin with a slash and you have to trust the server to add the rest of the path correctly. You are better off just putting in the full URL yourself

Did you find this article userful for your website?
If so, why not provide a link to it? Just copy the following to your web page:
      <a href='http://upwithabang.com/articles/http-redirect.html'>
Redirecting to another page
</a>

Share this:  del.icio.us icon