URL rewrite helps you to hide your extension name or show different extension name like index.php can be displayed as index.html or only index or home etc.
The following code will rewrite anyfile.php to anyfile.html
The following code will rewrite index.php to index
2. Rewrite product.php?id=12 to product/cat/12.html
3. Rewrite domain.com/member.php?username=arup to domain.com/susil
4. Rewrite domain.com/users.php?id=username&page=2 to domain.com/username/2
The following code will rewrite anyfile.php to anyfile.html
RewriteEngine on RewriteRule ^(.*)\.html$ $1.php
RewriteEngine on RewriteRule ^index index.php
Few Example to create SEO friendly URL.
1. Rewrite product.php?id=1 to product-1.htmlRewriteEngine on RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1
RewriteEngine on RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2
RewriteEngine on RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
RewriteEngine on RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ users.php?user=$1&page=$2 RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ users.php?user=$1&page=$2
This Tutorial is helpful for me .
ReplyDeleteIf Page are managed by admin suppose to create a xyz.php file which has not physical existence ..it might be aaa.php or anything else like mypage.java or something else . how to display it content in front end through using urlrewrite.
Thanks
With Regards
Kiran Agarwal
Hi kiran
Deleteif you want to call a page that doesn't actually exist but is pulled from the database,then
you typically redirect some part of the URL (mypage.php) to point into a $_GET variable used to access the database.
example : "mypage.php" here you should handles the database and displays
the correct data
write followint codes in .htaccess file:
//
RewriteEngine on
RewriteRule ^([A-Za-z0-9]+)\.php mypage.php?title=$1 [NC,QSA,L]
//
now you can fetch title by using $_GET['title'] in your mypage.php file
after getting title you can fetch the coresponding data from the data base and display in
mypage.php
For more information visit
Deletehttp://developers-portal.blogspot.in/2013/09/get-data-with-htaccess-url-rewrite.html