I really want to thank Mehdi LAANAIT for his suggestions concerning SEO (Search Engine Optimization).
Smart urls or search engine optimized urls allow bots like Google to identify keywords in urls. Website ranking then gets an added value. Parsing urls, title tags, description tags (keywords tags are now deprecated) and the body of a webpage allow search engines to rank web pages.
Including SEO concerns inside Web development requires
- Apache .htaccess changes
- urls changes
Building SEO-friendly URLs
Let’s assume a PHP website has to be re-written. Dynamic pages were formerly generated by PHP with the form :
to display articles belonging to category 1 (let’s say “kite photography”) and to subcategory 32 (“Rokkaku kites”). The problem with that url is that it does not tell the visitor or the bot about the content of the article. For SEO concerns, it should.
New urls will have to be generated throughout the website and be of the form :
The subdirectory “kites” doesn’t exist on the web server. It is only a virtual directory name generated by PHP for the sake of better SEO. The only thing the developer still has to manage is the way Apache server will treat the request to
Apache .htaccess : url rewriting
URL rewriting is the art of making php-generated urls human readable.
Apache’s .htaccess file will allow the developer to activate the Rewrite Engine which will analyse the url request and transform it into what’s necessary for the website not to end on a 404 error page.
This file will contain the following lines :
Options +FollowSymlinks -MultiViews #Line 1 : tells Apache to follow symbolic links
RewriteEngine on #Line 2 : activates RewriteEngine (Apache mod_rewrite module)
RewriteRule ^([a-z]+)/([a-z]+)$ index.php?cat=$1&scat=$2 [L] #Line 3 : rewriting rule
.htaccess Rewriting rule example
Apache will look for the string of characters between ^ et $ in the url.
This string is divided into :
- a number of lower case characters from a to z. This string will be stored in variable $1
- followed by a slash /
- followed by a number of lower case characters from a to z.This string is stored in variable $2
The second part of the rewriting rule is the php file Apache will load if the rewriting rule is to be applied :
index.php?cat=$1&scat=$2 [L] : flag [L] tells Apache to stop treatment without checking the following rewriting rules since the current rule drives the client to the right file.
Url rewriting is part of the solution to help google ranking your pages better. Back links, keyword selection, sitemaps, html tags (h1, strong, alt,…),… also contribute to a better ranking.
Once the developer has understood keywords are the key to success… let bots do their job…
Here are some non-wikipedia references :