Rewrite problem

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
scotty5000
Forum Newbie
Posts: 4
Joined: Fri Dec 05, 2008 7:35 am

Rewrite problem

Post 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
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Rewrite problem

Post 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
scotty5000
Forum Newbie
Posts: 4
Joined: Fri Dec 05, 2008 7:35 am

Re: Rewrite problem

Post 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.
scotty5000
Forum Newbie
Posts: 4
Joined: Fri Dec 05, 2008 7:35 am

Re: Rewrite problem

Post 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.
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: Rewrite problem

Post by GeertDD »

scotty5000
Forum Newbie
Posts: 4
Joined: Fri Dec 05, 2008 7:35 am

Re: Rewrite problem

Post 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.
Post Reply