Mod_Rewrite Rules You Should Know when use .htaccess file

mod_rewrite is used to change the incoming URL requests, dynamically, based on regular expression rules. Using this method you can map arbitrary URLs onto your internal URL structure as you like. so in the URL you can call the any string or html file which can be redirect on the php files, this is more useful for SEO purpose.

using .htaccess file you can write as many rules as you want, it means there is not limitation on the rules.  we can say that its supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule to provide a really flexible and powerful URL manipulation mechanism.

All rewrite rules which you write in the .htaccess file can apply on the Whole URL, it means its not only consider the filename but its also consider the path-info and query string if its in the url, and may be used in per-server per-virtualhost context (<VirtualHost> blocks), context (httpd.conf),   per-directory context (.htaccess files and <Directory> blocks). The rewritten result can lead to further rules, internal sub-processing, external request redirection, or proxy passthrough, depending on what flags you attach to the rules. The URL you redirect to is always relative to the directory in which your .htaccess file is placed. So if it’s in the parent directory, URLs are all in relation to the parent directory and if its in a subdirectory of parent directory then, URLs are in relation to that particular subdirectory.

Always keep in mind that .htaccess statements are case-sensitive. When you use Mod_rewrite in your .htaccess file. You need to put the below code at the beginning of your .htaccess file to turn mod_rewrite on, if you do not put this code then you htaccess file will not work as you want
RewriteEngine on

Synrax for a mod_rewrite statement is : RewriteRule Pattern Substitution [Flag(s)]

Example : 

RewriteRule ^freelancer.html$ freelancer.php   – This is a very basic rule that means any requests for freelancer.html will be sent to freelancer.php

Some time many user do not type the www and some time the site is not open but if you write below rules then its redirect on your domain even user write www or do not write www.

RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]