X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Help With Mod_rewrite    
post Dec 8 2016, 04:16 PM

UtterAccess VIP
Posts: 4,892
Joined: 25-September 02
From: Washington State

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:

currently returns the following file:

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 learned from him how to use mod_rewrite to parse an old-fashioned URL into $_GET[] variables. With this .htaccess script:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([A-Z­a-z­0-9­-]+)/?$ index.php?folder=$1 [L]
RewriteRule ^([A-Z­a-z­0-9­-]+)/([A-Z­a-z­0-9­-]+)/?$ index.php?folder=$1&page=$2 [L]
RewriteRule ^([A-Z­a-z­0-9­-]+)/([A-Z­a-z­0-9­-]+)/([A-Z­a-z­0-9­-]+)?$ index.php?folder=$1&page=$2&subPage=$3 [L]

and an old-fashioned URL like:

my index file in my root directory has the following vars available to it:

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.

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:
and the ?id value, even though it appears in the URL pane of the browser, isn't available to the script.

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 script. Anybody know how to do that?

Go to the top of the page
post Dec 10 2016, 05:44 PM

UtterAccess VIP
Posts: 4,892
Joined: 25-September 02
From: Washington State

I posted the same question on StackOverflow and got straightened out:


Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    13th December 2017 - 07:22 PM