Page 1 of 1

ORDER BY via URL variable - why is this failing?

Posted: Tue Mar 18, 2014 9:22 am
by simonmlewis

Code: Select all

http://test.local/seller/807&simon=y
My code isn't collating this $simon variable.

Code: Select all

$simon= isset($_GET['simon']) ? $_GET['simon'] : null;
echo "$simon";

echo "
<a href='/seller/$id&simon=y'>test</a>";
Are you now allowed to put a & after a number in the URL? I'm trying to run an "order by" based on a $sorder variable. But it won't work. so I tried it with $simon to see if that is passed through, but it isn't. I don't understand why. It's not echoing "$simon".

Re: ORDER BY via URL variable - why is this failing?

Posted: Tue Mar 18, 2014 9:46 am
by Celauran

Re: ORDER BY via URL variable - why is this failing?

Posted: Tue Mar 18, 2014 9:51 am
by simonmlewis
No that doesn't work either.
Changing the url to $id?simon=y, makes no difference.

Re: ORDER BY via URL variable - why is this failing?

Posted: Tue Mar 18, 2014 9:56 am
by Celauran
Sounds like the issue is with rewrite rules, then. What are those?

Re: ORDER BY via URL variable - why is this failing?

Posted: Tue Mar 18, 2014 10:00 am
by simonmlewis
This is the one that rewrites the seller products page:

Code: Select all

RewriteRule ^seller/([0-9]+) /index.php?page=productsseller&id=$1&menu=home [L]
And this is a category page - the 'sort' works on this one:

Code: Select all

RewriteRule ^categ/([0-9]+)/([^/]+) /index.php?page=categ&c=$1&cname=$2&menu=home [L]

Re: ORDER BY via URL variable - why is this failing?

Posted: Tue Mar 18, 2014 10:03 am
by Celauran
Missing QSA?

Re: ORDER BY via URL variable - why is this failing?

Posted: Tue Mar 18, 2014 11:00 am
by simonmlewis
I've not seen that before.

If I do this:

Code: Select all

RewriteRule ^seller/([0-9]*)? /index.php?page=productsseller&id=$1&menu=home [QSA]
The page is not found.
But this

Code: Select all

RewriteRule ^seller/([0-9]+) /index.php?page=productsseller&id=$1&menu=home [QSA]
Page is found, but the issue I have raised, remains.

Re: ORDER BY via URL variable - why is this failing?

Posted: Tue Mar 18, 2014 11:02 am
by simonmlewis
Incidentally, if I do this:

Code: Select all

RewriteRule ^categ/([0-9]+)/([^/]+) /index.php?page=categ&c=$1&cname=$2&menu=home [L]
And put ... &order=title, on the end of the rewritten URL, it works!!

Re: ORDER BY via URL variable - why is this failing?

Posted: Tue Mar 18, 2014 11:19 am
by Celauran
And if you do this?

Code: Select all

RewriteRule ^seller/([0-9]*)? /index.php?page=productsseller&id=$1&menu=home [QSA, L]

Re: ORDER BY via URL variable - why is this failing?

Posted: Tue Mar 18, 2014 12:31 pm
by simonmlewis
Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.
Error 500
site.local
Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.1

Code: Select all

DirectoryIndex index.php index.html index.htm 
order allow,deny
allow from all 

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

RewriteRule ^messages/([0-9]+) /index.php?page=messages&threadid=$1&menu=home [L]
RewriteRule ^seller/([0-9]*)? /index.php?page=productsseller&id=$1&menu=home [QSA, L]

Re: ORDER BY via URL variable - why is this failing?

Posted: Tue Mar 18, 2014 1:11 pm
by Celauran
Sorry, there shouldn't be a space between QSA and L.

Code: Select all

RewriteRule ^seller/([0-9]+)/? /index.php?page=productsseller&id=$1&menu=home [QSA,L]
works fine for me

Re: ORDER BY via URL variable - why is this failing?

Posted: Wed Mar 19, 2014 4:32 am
by simonmlewis
Well I'll be damned, it works.
What is the difference between using & with [L] and using it in that other method?
Is it a newer method?

Odd that the other way works on my category page, but not this page.

Re: ORDER BY via URL variable - why is this failing?

Posted: Wed Mar 19, 2014 8:34 am
by Celauran
They're different rules. QSA is query string appended, ensuring things don't get "lost" in the rewrite. L is last, meaning stop processing rules.

Re: ORDER BY via URL variable - why is this failing?

Posted: Wed Mar 19, 2014 8:39 am
by simonmlewis
So how is my category script working, if that uses the same "order" values in the URL?