Website Scripts And Cloud Tutorials

URL rewrite examples .htaccess

Byadmin

Mar 11, 2009 , , ,

Last updated on December 27th, 2015 at 11:44 am

Click to rate this tutorial!
[Total: 6 Average: 2.7]

Here are couple of examples for URL using  .htaccess
1)Rewriting user.php?id=12 to user-12.html

It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.

RewriteEngine on
RewriteRule ^user-([0-9]+)\.html$ user.php?id=$1

2) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz

Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1

Click to rate this tutorial!
[Total: 6 Average: 2.7]
8 thoughts on “URL rewrite examples .htaccess”
    1. Hi Murtaza,

      First question is whether you have changed/customized the rule according to your requirement. Here your URL looks like http://zameenmarket.com/view.php?ads=21, So basically the htaccess code will go like this

      RewriteEngine On
      RewriteRule ^([a-zA-Z0-9_-]+)$ view.php?ads=$1
      RewriteRule ^([a-zA-Z0-9_-]+)/$ view.php?ads=$1
      

      Update your .htaccess with the above rule. Make sure you save the.htaccess in your root directory or location where you have the view.php file placed. Then try to run this URL http://zameenmarket.com/22
      Hope this helps. If not get back to me with the details of what you have done.

      Regards
      Admin

Leave a Reply

Your email address will not be published.