corner image corner image
corner image corner image
corner image corner image
corner image corner image
corner image corner image
corner image corner image
corner image corner image

SEO friendly URLs with php, apache and mod-rewrite

Words used in URLs give tips to search engines about the content of the page. It also helps advertises figure out what the page is about. A URL that looks like node15 isn’t really optimized for search engines.

The most direct way to write SEO friendly  URLs is to use mod rewrite, where every URL is placed with the long descriptive format, and gets rewritten by apache to its corresponding non-friendly form. In a growing website, such a way will eventually overload apache as every rewriterule line gets treated as a regular expression, and executing regular expressions is not fast.

Better than that is to use only one rewriterule line in the .htaccess file of the form:

RewriteRule ^myscript* myscript.php

and inside myscript.php parsing $_SERVER[’REQUEST_URI’] will show the original request URI containing all the parameters. So for example:

http://www.mysite.com/myscript-some-many-parameters.html

will finally call your script, and the $_SERVER[’REQUEST_URI’] will contain ‘/myscript-some-many-parameters.html’, which then either you explode with ‘-’ or parse to retrieve your parameters back.

Technorati Tags: , , , , , ,

Tags: , , , , , ,

corner image corner image

corner image corner image

Leave a Reply

corner image corner image
1,361 spam comments
blocked by
Akismet