After receiving a positive response from my last post regarding the .htaccess mod_rewrite, I wanted to follow up with a post that contained a little more information on why the rewrite would be good to use, and a few descriptions about it’s syntax.

First off check out the following URL: http://www.example.com/products.php?category=umbrellas

What does this URL tell us? 1. The site uses php coding. 2. The site most likely uses the $_GET command 3. A few of the variables used to query the database are “category”.

Why do we care? By knowing the language that the code is written in, a hacker could pass it all sorts of data. If the right hacker knows the language your site is written in, they know just where to start, and if they want to get into your site (which they all do), then it is only a matter of time until your site is compromised.

By knowing that your page uses the $_Get command, and associated variables a hacker now knows just how commands are passed through your script and which variables communicate with your database.

OK, I think the point regarding the security angle, has been made. The technology that you’re using to run your site may not be a big security risk/threat. But what if you want to overhaul your site in the future.

What if you want to switch from PHP to ASP or something similiar? By having rewritten urls not limited by having file extensions, you can easily change languages or use multiple without having to worry about modifying existing links or wonder how long it will take the search engines to index your brand new pages.

By using the rewriting techniques we can easily re-write the URL to look something like this: http://www.example.com/category/umbrellas/

Now what do we know? Not much other than the umbrellas are in the category section.

One of my favorite reasons to rewrite URLs is to create a much more aesthetically pleasing URL to the user. By looking at the above URL, if the user needs to search for shoes, they can now simply type in the word “shoes” over the word umbrellas, and be brought to the page they want.

Another good reason is so the correct keywords related to the page appear in the URL. Search engines are now capable of indexing long dynamic URLs, but on smaller search engines, and even MSN, you can usually increase your site’s ranking by at least a few positions.

Here’s some explanations regarding the rewrite syntax:

The caret – ^ – This signifies the beginning of the URL string from the current directory. Pretty much all starts of a match, use a caret.

The dollar sign – $ – The dollar sign signifies the end of a URL string. This tells the rewrite to that it has reached the end of the input.

The backslash – / – The backslash is used to escape characters. Characters which require escaping are the period or dot. You’ll need to escape characters to tell Apache that the characters are normal and should be be used a URL.