Page 1 of 1

htaccess rewriteRule with ? symbol

Posted: Mon Nov 13, 2006 7:27 am
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

Posted: Mon Nov 13, 2006 8:18 am
by GeertDD

Posted: Mon Nov 13, 2006 8:53 am
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)

Posted: Tue Nov 14, 2006 5:06 am
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