I've been wondering how to do this for a while now. Basically, what I want to do is be able to use $_GET variables in the url without the messy symbols and stuff. Here's an example of what I mean. Instead of having to use: example.com/file.php?var=123 I want users to be able to use: example.com/123 If anybody could give me a solution for this, I would really appreciate it. Thanks, . Jordan .
Edit your .htaccess file (usually located in root path, if does'nt exist simply create a file named .htaccess), and place the following contents: RewriteEngine on RewriteRule ^(.*)$ file.php?var=$1 [L] Code (markup):
Is there no ways to do it within the script itself. Just that if I were to distibute the script, it would be a downside that customers have to edit that file every time.
Well that .htaccess file will automatically do each url (using regex) so long as the structure is the same. Unless you plan on changing the structure every 5 minutes, it shouldn't be necessary, just include all the rules that the person running the script would need, and it's good to go.
The thing is, if I distribute the script, some people who use it may not have the knowledge of editing .htaccess files. I'm looking to make it so that the user can easily just put the script on their site and that's it. Plus, there is only one file which will be using this so its no hassle to be doing it in php.
just include the .htaccess file with your script when distributing. It cant be done in php because t needs to be done before the request gets to php.
The thing is, I know it can be. I've seen it done before and just cant remember the script. Gonna have a play about and see if I get anything.
Maybe - http://phprewrite.randombase.com/ (however I don't have any experience with it and don't suggest this method)
The only other way is to pass all your 404 requests to the php file then parse its URI. Google this one. I have done it once or twice before.
Most servers will allow you to use URLs like this: example.com/file.php/123 You can then put code inside file.php that checks $_SERVER['PATH_INFO'] (or $_SERVER['REQUEST_URI'] if PATH_INFO isn't supported on your server) and obtains the query string from there.
hey try this one I take the function from drupal, hope it can help you function arg($index = NULL, $path = NULL) { static $arguments; if (!isset($path)) { $path = $_GET['q']; } if (!isset($arguments[$path])) { $arguments[$path] = explode('/', $path); } if (!isset($index)) { return $arguments[$path]; } if (isset($arguments[$path][$index])) { return $arguments[$path][$index]; } } PHP: and here is the .htaccess code <IfModule mod_rewrite.c> RewriteEngine on # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] </IfModule> Code (markup): enjoy it