htaccess rewriteRule with ? symbol

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
jggretton
Forum Newbie
Posts: 8
Joined: Fri Sep 15, 2006 7:14 am

htaccess rewriteRule with ? symbol

Post by jggretton »

Hello, I have urls like this:

Code: Select all

http://www.mydomain.com/products/ => http://www.mydomain.com/index.php?page1=products
But with non cookie sessions they become:

Code: Select all

http://www.mydomain.com/products/?PHPSESSID=sjdhf89sfd8 => http://www.mydomain.com/?page1=products?PHPSESSID=sjdhf89sfd8
The second '?' should be an '&' not a '?'

So i tried:

Code: Select all

RewriteRule ^(.*)\?PHPSESSID(.*)$ /$1&PHPSESSID$2 [L]
But it didn't work!!! Does anyone know what's going wrong!?

Thanks for any help you can give me,

James
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Post by GeertDD »

User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Your URL syntax is wrong. Missing an equal sign ( = ). And you can only use the question mark ( ? ) once, the second variable must be ampersand ( & ).

your code...

Code: Select all

RewriteRule ^(.*)\?PHPSESSID(.*)$ /$1&PHPSESSID$2 [L]
suggested change...
RewriteRule ^/(.*)/?PHPSESSID=(.*)$ /index.php?page1=$1&PHPSESSID=$2 [QSA, L]
you also need to write a rule for every senario, this means you need one without any session stuff and then one that handles if there is no trailing slash


(Moving topic to Web Servers since this is more about mod_rewrite than PHP code)
jggretton
Forum Newbie
Posts: 8
Joined: Fri Sep 15, 2006 7:14 am

Post by jggretton »

Thank you! QSA looks like the answer to much pain and suffering!!!

I'll also check out that new code, hopefully I'll manage to do all this without writing a separate rule for each scenario, but we'll see.

Thanks again for your help, I'll let you know how it goes,

James
Post Reply