SITUATION: I have a file-directory-based website with old-fashioned URLs, that I'm trying to convert to a system that doesn't require so many files and directories.
So, a URL like this: www.mysite.org/members/support/newmember/
currently returns the following file: www.mysite.org/members/support/newmember/index.php
This works but creates a need for far too many directories and index files.
While developing another site for a buddy who had too much work, I got from him a script that uses mod_rewrite to parse an old-fashioned URL into $_GET[] variables. With this .htaccess script:
Options +FollowSymLinks RewriteEngine on RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?folder=$1 [L] RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?folder=$1&page=$2 [L] RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ index.php?folder=$1&page=$2&subPage=$3 [L] and an old-fashioned URL like: www.mysite.org/members/support/newmember
my index file in my root directory has the following vars available to it: $_GET['folder'] $_GET['page'] $_GET['subPage']
and the script in the Index file simply assembles the correct includes according to the $_GET variables, thus eliminating the need for such an extensive file structure.
PROBLEM: Query strings are no longer available to the PHP script. Mod_rewrite has gobbled them up and spit out only the GET vars that are defined in the rules in .htaccess. This is okay for all the internal site links because I can abandon query strings and use my URL vars or SESSION vars to make values available to my pages. But the sticky issue remaining is that my site sends people to PayPal, and my scripts for that depend on the ? query string that PayPal sends back to my site. PayPal sends the user back with something like:
www.mysite.org/support/members/newmemberconfirmation?id=1234567
and the ?id value, even though it appears in the URL pane of the browser, isn't available to the script.
DESIRED SOLUTION: I don't know how to write scripts for mod-rewrite; I can't even make a regular expression very confidently. What I need is a script that assign the values between the slashes in the URL to GET vars, but will also make the original GET vars available to my PHP script. Anybody have a snippet for me that will do that?
index.phpin one rule and you'll see that$_SERVER['REQUEST_URI']contains what you need.