The web servers in your hosting plan put together your web pages, packages them up and ships them out to viewers who ask for them. They follow a very specific set of instructions from the web server software and the software that runs your website. But, what if you have a special situation where you want the server to do something different from the regular instructions? Here are some examples:

1. You reorganized your site, and some … or many … of your pages have new addresses. People out there are going to click links, from Google and other sites, that go to the old address. Normally, your web server would just send them an “OOOOPS! That page doesn’t exist” message. You need a way to tell the server, if people ask for this address, send them to this other address.

2. You have a secure certificate for your website, so your addresses start with https://, instead of http://. But you know that some people will get it wrong and go to http://. So, you want the server to show https:// either way.

These are the types of cases where the .htaccess file comes in handy.

For Scenario 1, there are two possibilities. If your new links, compared to your old links are in a very predictable pattern, you can use a Rewrite Rule. For example, if you change the name of a folder, but all the file names are the same, you can use code to go through the whole folder and just change the folder part of the address. But, if each of the files now has a new name, you will have to write a line of code for each file using 301 redirects.

In Scenario 2, you can use a Rewrite Rule … all requests that come in as http will show in the browser address bar and https and will be routed through the secure server.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.