Page 1 of 1

Rewrite problem

Posted: Fri Dec 05, 2008 7:45 am
by scotty5000
Hello everybody,

I am having a problem with a rewrite rule. It "should" turn this:

Code: Select all

http://www.example.com/test.html?var=123123
or:

Code: Select all

http://www.example.com/test.htm?var=123123
into this:

Code: Select all

http://www.example.com/display.php?page=test&var=123123
Here is the current rule that I am using that doesn't work:

Code: Select all

 
RewriteRule ^/(.*)\.(html|htm)\?lo=(.*) /display.php?pageID=$1var=$3
I have also tried this:

Code: Select all

 
RewriteRule ^/(.*)\.(html|htm)\?lo=(.*) /display.php?pageID=$1var=$2
but neither work. I have done some debugging and found that the problem seems to be with the \? but I can't figure out why. Any help would be greatly appreciated.

Thank you in advance,

Scott

Re: Rewrite problem

Posted: Fri Dec 05, 2008 8:01 am
by prometheuzz
What is "lo" doing in your regex:

Code: Select all

^/(.*)\.(html|htm)\?lo=(.*)
?

Try something like this:

Code: Select all

RewriteRule ^/(.*?)\.html?\?[^=]+=(.*) /display.php?pageID=$1var=$2

Re: Rewrite problem

Posted: Fri Dec 05, 2008 8:05 am
by scotty5000
Oops. That was supposed to be "var"....not "lo". I copied it from an older version. Thank you for your help. I will try that and let you know how it works.

Re: Rewrite problem

Posted: Fri Dec 05, 2008 8:25 am
by scotty5000
Still didn't work. I didn't think it would be related because I have an [L] on the end of the rule, but I have another rule below that one and i seems to always catch the second rule. Here is what I have in there:

Code: Select all

 
RewriteRule ^/(.*?)\.html?\?[^=]+=(.*) /display.php?pageID=$1var=$2 [L]
RewriteRule ^/(.*)\.(html|htm) /display.php?pageID=$1 [L]
Like I said, no matter whether I have the ?var=123123 on there or not, it always catches the second rule. What I really need is something that will put the &var=$2 on the end only if there is a ?var=1213 in the url; otherwise, it should just pull out the pageID.


Thanks again for your help.

Re: Rewrite problem

Posted: Sat Dec 06, 2008 12:44 am
by GeertDD

Re: Rewrite problem

Posted: Mon Dec 08, 2008 7:54 am
by scotty5000
Thank you GeertDD!!

Here is what I ended up doing:

RewriteRule ^/(.*)\.(html|htm) /display.php?pageID=$1&%{QUERY_STRING}

Thank you again everybody for all of your help.