passing variables via address bar

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

passing variables via address bar

Post by hannnndy »

hi friends

i want to pass variables using the address bar and not to use get method
for example :


http://www.parsitech.com/contact -- instead of --> http://www.parsitech.com?id=contact
http://www.parsitech.com/about -- instead of --> http://www.parsitech.com?id=about

i mean i want to pass variables and which are seemed there is not any variable there is not any contact directory for example but we call "http://www.parsitech.com/contact"

is there any way? :?:
Please help :wink:
Great thanks
Last edited by hannnndy on Wed May 14, 2008 6:59 am, edited 1 time in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: passing variables via address bar

Post by onion2k »

It's called "URL rewriting". How you do it really depends on your hosting environment. A common method is using Apache's mod_rewrite feature.
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

Re: passing variables via address bar

Post by hannnndy »

thanks for your reply
its a little un familiar to us we shoul change the apaches config or php would handle it if so how?
is there any other way?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: passing variables via address bar

Post by Eran »

you could create a simple rewrite rule to your index.php, and create your rewrite logic there. A process called 'bootstrapping' (google it)
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

Re: passing variables via address bar

Post by hannnndy »

thanks for the advice
i tried something like this

Code: Select all

 
RewriteEngine On 
rewritecond %{http_host} ^.* 
rewriteRule ^(.*) /index.php/$1
 
but it caused 500 nternal server error the problem is im so unfamilier to the htaccess and the coding of the it i tried it under windows server running apache : Apache 2.0 Handler and php 5.2.5

have you any real suggestion for me like the actual code or sample
:roll: :wink:
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: passing variables via address bar

Post by Eran »

Try something like this in your .htaccess:

Code: Select all

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
 
Now all requests but media, css and javascript will reach the index.php. In there you can parse them using something like:

Code: Select all

 
<?php
$id = $_SERVER['REQUEST_URI'];
 
To get the same results as you would with $_GET for your example (make sure to trim the '/' at the beginning).
Post Reply