473,419 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

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?name=harddisk


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

for all the products using .htaccess
Mar 19 '13 #1
3 18434
Niheel
2,460 Expert Mod 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine on
  2. RewriteRule ^item/(.*)?$ /products.php?name=$1

If you'd like to restrict the characters for item to letters & numbers you can use the following
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2. RewriteRule ^item/([a-zA-Z0-9]+)$ /products.php?name=$1
Mar 19 '13 #3
your html link:
Expand|Select|Wrap|Line Numbers
  1. <a href="www.example.com/item/harddisk">Hard disk</a>
Your .htaccess
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^item/(.*)$ products.php?name=$1
Your products.php
Expand|Select|Wrap|Line Numbers
  1. $name=$_GET['name']
Jan 10 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Nel | last post by:
Just looking for some general advice on modifying the URL for php. I am using .htaccess to allow a web site to translate example.html to index.php?content=example (below) ErrorDocument 404...
5
by: Mardy | last post by:
I have an aspx page that contains a drop down and 3 divs and lots of other stuff. I'd like to hide the divs depending on which option from the drop down is selected. It works fine until I do a...
13
by: nokan | last post by:
Hello! I'm trying to secure pdf-files from users that are not logged in on a site. What I have tried now is to make a .htaccess file in the directory where the pdf's are with "deny from all"...
2
by: RuthC | last post by:
Hi. I am using .htaccess to redirect in my website Now I want to redirect a url, which Contain '-' to another url. ex: RewriteRule ^book-and-magazine-discount/ query.php?q=$1.
0
by: RobertTheProgrammer | last post by:
Hi folks, I need to combine these two functions and I'm not sure how to go about it. I know how to use .htaccess to prevent anyone from hotlinking the images on my site. What I basically want...
6
by: Doug Laidlaw | last post by:
Jerry Stuckle wrote: I have never used anything but Apache, but I didn't know that .htaccess was server-specific. How does Windows do it? Doug.
6
by: vjayis | last post by:
Hi i m using htaccess to rewrite my urls., In this instead of http://www.mysite.com/index.php i want the url as http://www.mysite.com/home/ any ideas?? and also i m using the following...
3
by: canabatz | last post by:
Hello all!! i got a small problem ,not big :) i got this example of a link in my site that display everything correctly! http://www.mysite.com/product.php?id=200 now my problem is : if...
5
by: dhruvjha | last post by:
I'd like to take the following URL: http://www.website.com/index.php?url=about-us and turn it into : http://www.website.com/about-us and aso http://www.website.com/about-us.php I have...
4
by: neovantage | last post by:
hey all, can anybody tell me that how can i rewrite this URL http://74.52.129.114/~happybox/index.php?option=com_content&task=view&id=1 into this http://74.52.129.114/~happybox/about-us
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.