how to hide the id in url using .htaccess in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramrahila
    New Member
    • Mar 2013
    • 2

    how to hide the id in url using .htaccess in php

    in php with mysql

    i am having an url as www.domainname. com/products.php?na me=harddisk


    i want to change this url as
    www.domainname. com/item/harddisk

    for all the products using .htaccess
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Read http://zenverse.net/seo-friendly-urls-with-htaccess/

    Comment

    • Niheel
      Recognized Expert Moderator Top Contributor
      • Jul 2005
      • 2432

      #3
      First, you need a web server that allow you to do rewrites. For example, Apache Web Server with the mod_rewrite module.

      In your .htaccess file in the root direct you can use one of the follow basic rewrite instructions.

      A rewrite that will accept all characters after the forward slash:
      Code:
      RewriteEngine on
      RewriteRule ^item/(.*)?$ /products.php?name=$1

      If you'd like to restrict the characters for item to letters & numbers you can use the following
      Code:
      RewriteEngine On
      RewriteRule ^item/([a-zA-Z0-9]+)$ /products.php?name=$1
      Last edited by Niheel; Mar 19 '13, 07:02 AM.
      niheel @ bytes

      Comment

      • gurumoorthi
        New Member
        • Jan 2014
        • 3

        #4
        your html link:
        Code:
        <a href="www.example.com/item/harddisk">Hard disk</a>
        Your .htaccess
        Code:
        RewriteRule ^item/(.*)$ products.php?name=$1
        Your products.php
        Code:
        $name=$_GET['name']

        Comment

        Working...