Redirection using mod_rewrite

Redirecting websites or web pages using Apache mod_rewrite

Mod_rewrite is a module of the Apache Web Server, and for the purposes being discussed here, the redirect capability serves the function of instructing the server how to handle delivering the location of specific pages or sites to user agents, either web browsers or search engine spiders.

As with all server-side functions or programs, mod_rewrite operates at the server level, before the page is ever delivered to the user agent, either a browser or search engine spider, so it's a completely transparent operation.

Redirecting pages using mod_rewrite is is done by putting a few lines of code into a file called .htaccess which goes into the root directory of the site. First you'll have to make sure you're on an Apache Web Server that supports mod_rewrite, and create an .htaccess file. If your web host doesn't support .htaccess or mod_rewrite, it may be time to change hosts.

This is strictly for Apache web servers; if you're on M$ hosting you're on your own.

Apache's mod_rewrite and Front Page Extensions sometimes don't play well together at all.

If you host your site on IIS/Microsoft Server, there is an equivalent that you can find out about by doing a search at your favorite search engine.

Types of Redirection: Temporary and Permanent

There are two types of server-side redirection, and each of them returns different server header codes and sends a different "signal" especially important for search engine indexing purposes:

  • Permanent redirection: 301 Redirect
  • Temporary redirection: 302 Redirect:

Using 302 is what most domain registrars do when "pointing" pages, and while it's beyond the scope of what we're looking at here, 302 temporary redirects are not a good thing at all where search engines are concerned.

Reasons to Redirect

Redirection can be done for a number of reasons, including:

  • Redirecting the Homepage

  • Redirecting When a Page Has Moved

  • Using Redirection When a Site is Moved to Another Domain

Yes, mod_rewrite is Rocket Science

After all is said and done, in my opinion using .htacess or mod_rewrite IS rocket science, with all the little symbols and squidgets. But as long as the server supports mod_rewrite (and if yours doesn't it may be time to change hosts) it's simple enough to copy and paste a couple of lines of code that will accomplish just what we need.

Redirection Using Mod_Rewrite | Redirecting the Homepage
Redirecting Web Pages using mod_alias | Creating an .htaccess file
File Sizes | Web Safe Colors

Official Documentation for URL Rewriting with Apache HTTP Server