making clean urls using PHP ??
Moderator: General Moderators
making clean urls using PHP ??
Hello forums !!
I am bored with working with the url with query string urls ie("http://localhost/my_project/index.php?p ... ion=create").
Now i would like to work with clean urls like "http://localhost/my_project/test/create"
I would like to rewrite the url without using mod_rewrite module rather i would like to use PHP.
How to explode the urls to get the required parameters ?
Note: I am working under the my_project folder
Any comments n suggestions are warmly welcome.
Thanks in advance to all of you.
I am bored with working with the url with query string urls ie("http://localhost/my_project/index.php?p ... ion=create").
Now i would like to work with clean urls like "http://localhost/my_project/test/create"
I would like to rewrite the url without using mod_rewrite module rather i would like to use PHP.
How to explode the urls to get the required parameters ?
Note: I am working under the my_project folder
Any comments n suggestions are warmly welcome.
Thanks in advance to all of you.
There's this class for making safe strings to pass as a URL component, from user entered strings. However that uses a .htaccess rule (could be configured not to, of course). Just thought I'd throw that in there because I wrote it. 
I think what you want to do is explode('/' , $_SERVER['PATH_INFO']). I might have the wrong server array index, though.
I think what you want to do is explode('/' , $_SERVER['PATH_INFO']). I might have the wrong server array index, though.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I use a .htaccess like this:
And then check $_SERVER['PATH_INFO'], however you may need to get that information from other globals depending on your sever configuration and whether you are in the root directory or in a sub directory.
Code: Select all
RewriteEngine on
RewriteRule !\.[a-zA-Z0-9]{2,4}$ index.php(#10850)
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
oh !!! so URLs can be parsed by scipt??
it means if http://somedomain.net/folder1/folder2/floder3/
may not 100% imply that there i am requesting for a file of folder3 which is in folder2 which is in folder1
is it???
if so.. I am very happy..
till now i was thinking that http://somedomain.net/var1=kk&var2=bk as only way to send variables from client to server.
1. kindly tell me what are all the ways URL parsing can be done.??
2. please tell me the package of php for url parsing.
it means if http://somedomain.net/folder1/folder2/floder3/
may not 100% imply that there i am requesting for a file of folder3 which is in folder2 which is in folder1
is it???
if so.. I am very happy..
till now i was thinking that http://somedomain.net/var1=kk&var2=bk as only way to send variables from client to server.
1. kindly tell me what are all the ways URL parsing can be done.??
2. please tell me the package of php for url parsing.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
The Zend Framework uses a .htaccess file to redirect everything to an index.php file (called a bootstrap file) which then works out what you want to do, what parameters are etc. At it's basic level it is fairly easy to do/implement. The Zend Framework itself however has more work to be done on handling "views"/output of pages in regards to templating but this is probably a personal view.
I'think . path_info can help u
not need MOD_REWRITE.
NOT APAHCE SUPPORT
use $_SERVER['"PATH_INFO"].
BUT one thing need say to u that is THE php file should have no ext (it just mean apache need support no ext.)
the code below is my site used.
the emg like this : http://www.play-games-online.cn/play-ga ... _1_1_10897
BUT MY SITE is used a host not server. So only be play-game.php. this shoulded be play-game/1_1_1_10897
not need MOD_REWRITE.
NOT APAHCE SUPPORT
use $_SERVER['"PATH_INFO"].
BUT one thing need say to u that is THE php file should have no ext (it just mean apache need support no ext.)
the code below is my site used.
Code: Select all
if(@$path_info =$_SERVER["PATH_INFO"]){
if(preg_match("/\/(\d+)_(\d+)_(\d+)_(\d+)$/si",$path_info,$arr_path)){
$gid =intval($arr_path[1]);
$fid =intval($arr_path[2]);
$sid =intval($arr_path[3]);
$gameid =intval($arr_path[4]);
}else header('location:/');
}else header('location:/');BUT MY SITE is used a host not server. So only be play-game.php. this shoulded be play-game/1_1_1_10897
AOL Speak
can [s]u[/s] YOU [s]plz[/s] PLEASE tell me what does this regex do ??
RewriteRule !\.[a-zA-Z0-9]{2,4}$ index.php
RewriteRule !\.[a-zA-Z0-9]{2,4}$ index.php
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Regardless of the way your app handles URL fetching, handling, production, etc, your server will need a way to map all incoming requests to a single file. This is commonly done with a .htaccess file in Apache in a shared hosting environment. If you manage your own Apache web server, you can add the rewrite rules to the httpd.conf directly and remove the need for a .htaccess file.
I am not sure how to handle request mapping in other servers.
I am not sure how to handle request mapping in other servers.
Pardon me..
i think PATH_INFO only works if i had following url
http://localhost/my_project/index.php/test/create
not if we use
http://localhost/my_project/test/create
Any idea ??
i think PATH_INFO only works if i had following url
http://localhost/my_project/index.php/test/create
not if we use
http://localhost/my_project/test/create
Any idea ??
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
So add the .htaccess I gave you above and see what you get. Create an index.php that looks like this:PHPycho wrote:Pardon me..
i think PATH_INFO only works if i had following url
http://localhost/my_project/index.php/test/create
not if we use
http://localhost/my_project/test/create
Any idea ??
Code: Select all
<?php
phpinfo();(#10850)