PDA

View Full Version : mod_rewrite RegExp Help Please


johnnyb
02-16-2007, 11:24 PM
Hi,

I have a rewrite rule running well, except for one or two issues. Here's the rule as it currently reads:
RewriteRule ^([^/]*)?(/)?teach/?(.*)?$ admin/$3?sn=$1
What I'm trying to do is use the stuff before '/teach/' as an identifier that gets passed to the PHP as a $_GET variable.

However, I want to be able to still have access to any real $_GET variables I set. For example, if I have this URL in the browser:

mysite.com/folder/teach/index.php?log=logout

I lose the log=logout in the $_GET. Can you folks who are better at RegExp than I am help me write the right thing?

Thanks a lot,

John

johnnyb
02-17-2007, 07:42 PM
I solved my problem. I was losing the $_GET because Apache treats the querystring as separate from the URL. To preserve the querystring, (or part of it), you need to add it to the rewrite rule.

My RewriteRule now looks like this:
RewriteRule ^([^/]*)?(/)?teach/?([^?]*)(\?)?(.*)?$ admin/$3?sn=$1&%{QUERY_STRING}