Creating Search Engine Friendly URLs with PHP - Rewritten URLs
(Page 3 of 4 )
If your URLs are spidered and indexed properly, there is no need to restructure them. Keywords in the URL do not add much to rankings. Restructuring is only necessary if search bots have trouble spidering your website or if you’re developing a website from the ground up.
If you do restructure, then it is necessary to redirect old URLs to a new location in order to maintain at least some link power. Do not get too obsessed with rewriting. If you use underscores instead of dashes, there is no reason whatsoever to migrate to dashes.
An example of URLs rewritten to be static URLs:
http://example.com/cars/acura/TL/
http://example.com/cars/bmw/323.thml
Dynamic parameters are removed and hidden in a static URL. This can be achieved with mod_rewrite. The rewriting process only hides parameters and presents a static structure to the bots. This approach is relatively difficult to implement, as it requires interaction with the database to extract the copy for the URL.
Here are some general rules for rewriting URLs.
Spaces should be converted to a slash.
Dashes should be selected over underscores. Although there’s little difference, search engines used to treat underscores as a separate character, while dashes were treated as a space. This has changed.
Try to maintain a consistent style with all URLs.
Rewriting
When you rewrite PHP URLs you are keeping the actual URL commands intact. For example, PHP script will understand the following and execute the command accordingly:
but it will give a 404 error for the following URL:
The rewritten URLs don’t actually exist anywhere on the server. The server still has a script which expects to receive commands through the URL string and generate pages depending on those commands. URL rewriting lets you convert PHP URLs to a set of more "natural" links with a static look.
Remember that you will need to redirect old URLs to the new location in order to maintain link equity (inbound and outbound) and to prevent 404 errors.
You will also need to modify your internal link structure.
The standard for URL rewriting in the Apache world is mod_rewrite, which is why we are using it in this article.
The Apache module mod_rewrite is a killer; it is a really sophisticated module which provides a powerful way to do URL manipulation. With it you can do just about any type of URL manipulation you can think of. The price you have to pay is to accept complexity, because mod_rewrite's major drawback is that it is not easy for a beginner to understand and use. And even Apache experts sometimes discover new aspects where mod_rewrite can help.
In other words, with mod_rewrite you either shoot yourself in the foot the first time and never use it again, or love it for the rest of your life because of its power.
You do need to know some code to pull this one off.
Here’s some info on mod rewrite:
I assume that you’re using an external host, which means that 99.99% of time mod_rewrite is already installed. If not, then Google will save you. Just look up "installing mod rewrite."
Once you enable mod_rewrite, create a file called .htaccess and put it into the directory of your application. You can also choose to use httpd.conf instead of .htaccess, which has subtle differences. If you choose to go with httpd.conf, then you will need to place rewrite rules inside the <VirtualHost> element of the httpd.conf. Also keep in mind that a slash (/) will be considered to be part of the URL.
On the other hand, .htaccess is perfect if you don’t have access to the configuration file (httpd.conf), you want customized options for a particular directory or want to be able to change options without restarting Apache server. You cannot restart the server if you’re using shared hosting. In this article I assume you’re using .htaccess.
Next: A Basic URL Rewrite >>
More Search Optimization Articles
More By Ivan Strouchliak