Left Quote    Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln    
Right Quote
[login] | [Register]

Mod_Rewrite URLs for Search Engines

by: bs0d
Page: 1 of 3
(View All)

Mod_Rewrite URL's for Search Engines

Mod_Rewrite is a module in Apache webservers that allows you to manipulate URL's. Mod_Rewrite can be quite powerful, and is known as a "voodoo" tool and "the swiss army knife of url manipulation." In this tutorial, Im going to cover using Mod_Rewrite and regex to increase hits to your site from search engines (like Google) by making them search engine friendly.

Should I? or Shouldn't I?

Search engines will not crawl deep into query strings. Im saying deep because it is true that the spider will crawl a query string a bit, but this is overall a good decision in other areas as well, take a look:
  1. Google can get meaning from your url's, and can be searched accordingly.
    Say you used a query string to refer to an article on your site like, /id=45. Well, id=45 does not tell google anything! If you changed that to, /study-on-science/ --Then google can read that, and if someone searches science, or study; it is likely to show up.
  2. It is easy to read!
    By appearance alone, it looks more professional and pleasing to the eye, than a bunch of confusing numbers and characters. Your visitors can be able to recall an article more easily by its url, than dealing with memorizing query strings. Also, many popular sites today use this method.
  3. More hits to your site.
    We cannot ignore the fact that doing this is going to increase hits to your website. If your site is new, its important to let everyone know that its out there. Because of the reasons above, the hits to your site will increase, as well as the rank.
Everyone has their own opinion on this, but I feel it is important and can help your site out. It is also quite easy once you get the hang of it, so why not try? If you use query strings in your URL's and do not re-write them, you're only hindering your site from deserved hits for appropriate content via searches on search engines.

So if you're reading this tutorial you've found that search engines do not like query strings, and deal much better with text based directories. So if we make your urls look like this:

Then the search engines will be more than happy to make that information available in searches.

Getting Started

First, lets assume that the url's to your site currently look a bit like this:

our goal and final product, is to make that same file accessible by a prettier and friendlier url like this:

Ok, to eliminate problems that may occur when you begin the re-writing process, lets make sure that everything is set up right, so we can know that it have to be the code producing errors, not anything else if something goes wrong.

The mod_rewrite module must be loaded.

*Note: If you're running your own webserver, you can check by navigating to the httpd.conf file and opening it. On line 182 (Apache 1.3x), make sure it reads:

and that its not commented out (does not have # in front of it). If it does, remove the #. Now go to line 226. It should read:

If it has a # in front, remove it. Now it will be loaded when you start Apache. You can restart apache to ensure the changes go into effect, assuming that you made any.

If you're not running on your own webserver (most likely), then you will likely not have to bother with any of that stuff, because it is probably already setup for you by the server administrator. If it still wont work and you feel your code is correct, you can try inserting this:

as the first line of you .htaccess file.

The magic happens so to speak in your .htaccess file. You can make the changes for all the rewrite rules in the .htaccess of your root folder, or to the folder which you want to apply the changes, it doesn't matter either way.

1  |  2  |  3  |  
Next »

No Comments for this page.

You Must be logged in or a member to comment.

Tutorial Stats

Tutorial Stats

0 Total Comments
5 Rating of 5 (1 Votes)


Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article



Your Article Here

"" Copyright © 2002-2021; All rights lefted, all lefts righted.
Privacy Policy