In this tutorial I am going to explain the process ‘ How can we change the URLs in a SEO friendly URLs with the help of PHP, mod_rewrite and .htaccess in Apache’.
This is the very good and simple way to create a SEO friendly website with dynamic content.
Basically mod_rewrite is an Apache module and it takes care of rewriting URLs, like
http://www.example.com/page.php?id=2 convert in to http://www.example.com/page/2.html
To turn on the module use mod_rewrite in first line in htaccess using below line
RewriteEngine on
Now start with very simple htaccess.
RewriteEngine On RewriteRule ^page/([0-9]).html$ /page.php?id=$1
Actual mod_rewrite rule is line 2.
RewriteRule ^page/([0-9]).html$ redirect to /page.php?id=$1
When you call the http://www.example.com/page/2.html it will call the dynamic urls
http://www.example.com/page.php?id=2
Here RewriteRule ^page/
([0-9]).html$ call the number value which is ID in URL.
You can call multiple numbers on this rule like below
RewriteRule ^page/([0-9])/([0-9]).html$ /page.php?id=$1&pagenum=$2
After that URL look like below
http://www.example.com/page/2/3.html it will call the dynamic urls
http://www.example.com/page.php?id=2&pagenum=3
And you get the two variable
1. id
2. pagenum
You can call these variable and show the actual page results.