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

VN:F [1.9.22_1171]
Rating: 5.0/10 (6 votes cast)

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

VN:F [1.9.22_1171]
Rating: 5.0/10 (6 votes cast)
8 thoughts on “URL rewrite examples .htaccess”
  1. Hello all
    I am new to this board but this is superbbbbbbbbbbbbb

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
  2. Hello all
    I am new to this board, a good one.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
  3. Hi admin i put your code on my web but it not work this code

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

    this my url it not change http://khmerera.com/detail?ads=22 it show detail too how can i do cos i want hide detail i want show like this http://khmerera.com/?ads=22 help me please Thz!

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    1. Hi Sovann,

      Thanks for your comment,
      Try this

      RewriteEngine On
      RewriteRule ^ads=([a-zA-Z0-9_-]+)$ detail.php?ads=$1 [NC,L] # Handle product requests
      

      Your URL should look like this
      http://khmerera.com/ads=22

      Hope you are fine with this.
      Regards
      Admin[Mistonline.in]

      VN:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)
  4. Hi , i am using your code on my web but it not work this code

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

    this my url it not change http://zameenmarket.com/view.php?ads=21 it show detail too how can i do this becoz i want hide detail i want show like this http://zameenmarket.com/22
    where i am wrong help me please

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    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

      VN:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)

Leave a Reply

Your email address will not be published. Required fields are marked *