Jump to content

$_GET stopped working after rewrite


jacko310592

Recommended Posts

hey guys

 

i have this rewrite code:

RewriteRule ^(.+)/pictures/(.+)?$ profile/pictures.php?$1 [NC,L]

which rewrites "mysite.com/profile/pictures.php"  to  "mysite.com/USER/pictures/ID/"

 

but a problem i have just found with it is that i need to be able to use a get vairable for a current page number, so the url would be like:

"mysite.com/USER/pictures/ID/?page=1"

 

but its no longer getting any get variables (in php)

 

can anyone suggest how this can be solved, thanks

Link to comment
https://forums.phpfreaks.com/topic/201425-_get-stopped-working-after-rewrite/
Share on other sites

hmm, how strange.

 

with the rewite rule being..

RewriteRule ^(.+)/pictures/(.+)?$ profile/pictures.php?$1 [NC,L,QSA]

 

and php code being $_GET['page']

 

and the URL of mysite.com/USER/pictures/ID/?page=2

 

gives me nothing in the output (output being the echo of the GET)

 

are there any settings/code im missing to recognise variables after the '?'

It's perhaps because your current pattern is malformed. A query_string should consist of key/value pairs. In your RewriteRule you are moving the first folder name to the query_string, but is this supposed to be a key or a pair?

 

RewriteRule ^(.+)/pictures/(.+)?$ profile/pictures.php?something=$1 [NC,QSA,L]
# or
RewriteRule ^(.+)/pictures/(.+)?$ profile/pictures.php?$1=something [NC,QSA,L]


erm, im not too sure what you mean, sorry.

 

 

when i tried the following rewrite code:

RewriteRule ^(.+)/pictures/(.+)?$ profile/pictures.php?user=$1&id=$2&page=$3 [NC,QSA,L]

 

i got these results when using echo on the GET variables:

$_GET[user]  >>  profile/index.php

$_GET[id]      >>  150/

$_GET


  >>  (Blank)

 

that was when using this URL

http://localhost/jacko310592/pictures/150/?page=1

 

so my pattern must be malformed, i just dont see how :/

oh, just removed a piece of code (earlier on in my htaccess) and it works fine now,  but what with the following code was casuing this problem?

 

RewriteRule ^(.+)/?$ profile/index.php?$1 [NC]

 

 

thanks again cags, and sorry i hadnt tried this earlier

 

 

EDIT:

the above code is to rewrite "mysite.com/profile/index.php"  to  "mysite.com/USER/"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.