A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearBest way to get data from “clean” and “dirty” URLs - page 1
User InfoPosts
Best way to get data from “clean” and “dirty” URLs#1
I(m writing an application that gets data from URLs, but I want to make it an option whether or not the user uses "clean" urls (ex: http://example.com/hello/world) or "dirty" urls (ex: http://example.com/?action=hello&sub=world).

What would be the best way to get variables form both URL schemes?

posted date: 2008-12-31 11:08:00


Re: Best way to get data from “clean” and “dirty” URLs#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-31 11:08:01


Re: Best way to get data from “clean” and “dirty” URLs#3
Is it only these two options? Or can you have example.com/hello?sub=world or example.com/world/hello? What about example.com/hello/world?action=somethingelse&sub=different?

posted date: 2008-12-31 11:14:00


Re: Best way to get data from “clean” and “dirty” URLs#4
sounds like a pain, but i guess create a function that analyzes the URL for every request. First determine if it(s "dirty" or "clean" URL. For that, I would first look for the presence of the question mark character and proceed from there (additional checking will obviously be requried). For the "dirty" URL, use PHP(s normal Get method retrieval capabilities ($variable_name). For the "clean" one, I would use Regular Expressions. That would be the most flexible (and efficient) way to parse the URL and extract potential variables.

posted date: 2008-12-31 11:15:00


Re: Best way to get data from “clean” and “dirty” URLs#5
If your mod_rewrite has a rule like the following:RewriteRule ^hello/world /?action=hello&sub=world [NC,L]or, the more generalised:// Assuming only lowercase letters in action & sub..RewriteRule ^([a-z]+)/([a-z]+) /?action=$1&sub=$2 [NC,L]then the same PHP script is being called, with the $_REQUEST variables available whichever way the user accesses the page (dirty or clean url). We recently moved a large part of our site to clean urls (still supporting the older, "dirty" urls) and rules like the above meant we didn(t have to rewrite any code that relied on $_REQUEST params, only the mod_rewrite rules.UpdateMod_rewrite is an Apache module, but there are a number of options available for IIS also. Whichever web server you decide to support, the mod_rewrite approach will likely result in the least amount of work for you. Without it, you(d likely have to create a load of files to mimic the structure of your clean urls, e.g. in your webserver root you(d create a directory hello, placing a file world into it, containing something like the following:// Set the $_REQUEST params to mimic dirty url$_REQUEST[(action(] = (hello(;$_REQUEST[(sub(] = (world(;// Include existing file so we don(t need to re-do our logic// (assuming index.php at web root)include((../index.php();As the number of parameters you wish to handle (cleanly( increases, so will the number of directories and stub files you require, which will greatly increase your maintenance burden.mod_rewrite is designed for exactly this sort of problem, and is now supported on IIS as well as Apache, so I(d strongly recommend going in that direction!

posted date: 2008-12-31 11:29:00


Re: Best way to get data from “clean” and “dirty” URLs#6
A quick and dirty way might be to simply check for GET variables. If there are any, it(s dirty, if not, it(s clean. Of course this depends on what exactly you mean by dirty URLs.

posted date: 2008-12-31 11:31:00


Re: Best way to get data from “clean” and “dirty” URLs#7
The only problem here is that I want to support more than just Apache, so using a .htaccess wouldn't work.

posted date: 2008-12-31 11:51:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.