Writing SEO Friendly URLs using .htaccess on Virtual Machine
A friendly URL accurately describes the page using keywords that are easy to read for both search engines and users. The URL is also shown in the search results and keep this point in mind i.e well crafted URLs are more informative and attractive to users and this means higher Click Through Rates.
It's much simpler task you need to maintain your URL much small and with good keyword as a parameter so that the page will be indexed well by the search engines.
User will come to know what informations will be present under such url.
So use the below sample example code to configure seo friendly url:
Normal practice of using url:
Our major work is to rewrite it as:
This can be achieved by creating new htaccess file and add these lines:
RewriteRule ^user/([0-9]+) user.php?u=$1 [NC, L]
RewriteRule ^user/([0-9]+)/([0-9a-zA-Z]+) user.php?u=$1&cat=$2 [NC, L]
rewirteRule ^page page.php
Let us ellaborate above code,
RewriteEngine: To enable we need to enable rewrite engine on.
RewriteRule: The RewriteRule directive is the real rewriting of rules that need to be executed.
$1 and $2 : Are variable used to represent dynamic values which we are pass in url against id and category.First ([0-9]+) represent $1 and second ([0-9a-zA-Z]+) represent $2 (from left to right) and so on.
NC: Non case sensitive pattern match.
L : It will stop the rewriting process immediately and you should not apply any more rules after this.
RewriteBase : It specifies the URL prefix to be used. If your project inside some folder say myproject than you can write like this: