473,498 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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 18473
Niheel
2,456 Recognized Expert Moderator Top Contributor
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
gurumoorthi
3 New Member
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
3675
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
2820
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
1809
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
1742
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
1938
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
1726
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
8891
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
2426
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
4503
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
2519
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
0
7002
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
7165
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
7205
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...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5462
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,...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4590
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...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.