You have had to change the file extension explicitly but in this post I’m going to show you how to rewrite the URL instead of renaming the file extension Using this technique you will see example.html in the address bar of the browser but the actual file name remains example.php and you don’t need to rename the file extension. Furthermore you can rewrite the URL like example.php?id=5 to example-5.html.
Benefits of rewriting URL:
When a search engine visits the dynamic url like example.php?id=5 it does not give much importance to that URL as search engine sees “?” sign treat it as a url which keeps on changing. so we’re converting the dynamic URL like the example.php?id=5 to static url format like example-5.html. We’ll rewrite the url in such a way that in browser’s address bar it will display as a example-5.html but it actually calls the file example.php?id=5. So that why these kind of URL also named as SEO friendly URL.
Requirement for URL Rewrite:
To rewrite the URL you must have the mod_rewrite module must be loaded in apache server. And furthermore, FollowSymLinks options also need to be enabled otherwise you may encounter 500 Internal Sever Error.
Examples of url rewriting for seo friendly URL
For rewriting the URL,
Step 1: you should create a .htaccess file in the root folder of your web directory.
Step 2: And have to put the following codes as your requirement.
Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)\.htm$ $1.php [nc]
The following example will rewrite the test.php to test.html i.e when a URL like http://localhost/test.htm is called in address bar it calls the file test.php. As you can see the regular expression in first part of the RewriteRule command and $1 represents the first regular expression of the part of the RewriteRule and [nc] means not case sensitive.
Options +FollowSymlinks RewriteEngine on RewriteRule ^example-([0-9]+)\.html$ examples.php?id=$1
The following example will rewrite the example.php?id=5 to porduct-5.html i.e when a URL like http://localhost/example-5.html calls example.php?id=5 automatically.
This also may help you
RewriteCond %{REQUEST_FILENAME} =-f RewriteRule ^(.*)\.php$ $1.html [NC,L] RewriteRule ^(.*)\.html$ $1.php [NC,L]
its really make excited!!!!!!