473,680 Members | 3,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

URL use "/" instead of "?" to send variables

rahulephp
59 New Member
Hi,
In normal php, We use ?id=123 to send variable through URL.

So, the URL would be www.example.com/page.php?id=123 and then we use $_REQUEST['id'] to receive the variable on another page.

But my question is, if I use "/" instead of "?" (Ex: www.example.com/page.php/id/123), then how to receive the "id" on page.php.

$_REQUEST['id'] doesn't works in this case.

Thank you in advance
Jun 21 '10 #1
11 3333
code green
1,726 Recognized Expert Top Contributor
$_REQUEST['id'] doesn't works in this case.
Does the browser still go to page.php in this case?
I doubt it.
Jun 21 '10 #2
rahulephp
59 New Member
Not sure.
But i have seen these kind of URL's in lots of websites and just wondering if it'll be possible in any ways.
Jun 21 '10 #3
code green
1,726 Recognized Expert Top Contributor
i think mod_rewrite allows this.
Don't know much about it but Apache only
Jun 21 '10 #4
rahulephp
59 New Member
I tested the above code and it shows 404 error page.
Yes, I need to modify .htaccess file

Can anyone please assist me how to modify .htaccess file to remove the "?"

I'll be thankful to you
Jun 21 '10 #5
ronsplinter
1 New Member
@rahulephp
this is done by the rewrite module of apache and this handles regular expressions. You have to put a rule like this in your .htaccess file on the root of your website:

RewriteRule ^product/([0-9]+)$ /page.php?id=$1

^ means the start of the url after www.example.com/
$ means the end of the page.

www.example.com/product/123 will be converted by the server to: www.example.com/page.php?id=123

In PHP you use the normal $_GET['id'] variable. The rewrite module must be enabled by apache... This is mostly used to make the url format independent of the serverside scripting language so the .php in the url is not logical. Thats why i changed it to product/ . The .htaccess starts with

RewriteEngine On
Options +FollowSymLinks
RewriteBase /
Here all the rewrite rules..
...
...

Hope this will help you on your way.
Jun 21 '10 #6
rahulephp
59 New Member
@ronsplinter
Thanks ronsplinter,
This is one of the best answer i was searching for.
Jun 21 '10 #7
HaLo2FrEeEk
404 Contributor
There are nearly limitless things you can do with mod_rewrite under Apache. For example, I have a click counter on my site that keeps track of the number of clicks to each linked news post, using a link id. Originally the URL looked like this:

http://mysite.com/clicky.php?id=###

I wanted it to be more search engine-friendly, so I rewrote it to this:

http://mysite.com/news###/title_of_news_post.php

It still goes to the original click.ph URL, but the user doesn't know that, and Google indexes thestatic-looking link a lot more easily.

I'm in the process or rewriting my entire site to use mod_rewritten URLs, to improve SEO.
Jun 21 '10 #8
rahulephp
59 New Member
@HaLo2FrEeEk
Hey HaLo2FrEeEk,
if you are going to rewrite your entire site to use mod_rewritten URLs and if your website has ranked in SERP for good keywords then think it once. The URLs of all you website pages will be changed and the URLS will suppose to be new pages. And in that case you'll lost your previous ranking.
Jun 22 '10 #9
rahulephp
59 New Member
I'm thankful for your good response on this but now i want to close the topic here.
Thanks once again
Jun 22 '10 #10

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

Similar topics

94
30292
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock Statement (C# Reference) statement to serialize access. " But when is it better to use "volatile" instead of "lock" ?
0
8558
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9030
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8912
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8734
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7565
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5783
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4296
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2183
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.