Page 1 of 1
PHP $_POST variables (oh and DAMNED htaccess)
Posted: Tue Nov 25, 2008 11:21 am
by the moose
hi there guys
long time lurker - first time poster!!
it involves .htaccess so of course -
ok - so i am building a site - being all SEO friendly and so on so of course am using the htaccess to turn:
Code: Select all
http://www.mydomain.com/Extra Bit Here
into:
Code: Select all
http://www.mydomain.com/page.php?bit=Extra Bit Here
This, much to my amazement is working 100% perfectly!!!
Anyway, now I am implementing paging on that, and what i had (pre .htaccess) was that it would go to:
Code: Select all
page.php?bit=Extra Bit Here&page=2
(for page 2 etc)
again, that was working nicely!!
Ok, now what I would REALLY like to do is to change it so that the page number is not shown in the URL but still, obviously set the variable.
I realise that I can't "invisibly" set the $_GET variables, but is there any way of setting the $_POST variables using just a text link? I guess I could use a form to do this, but would seem a little pointless!!
Maybe there is another route to go down?? I would really rather not have to have:
Code: Select all
http://www.mydomain.com/Extra Bit Here/2
for page 2 using htaccess (not that I could get that to work anyway!!!!

)
Anyway, any help would be gratefully received.
Cheers
The Moose
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Tue Nov 25, 2008 12:33 pm
by pickle
Welcome!
To answer your question: no - .htaccess & redirects can only set properties in the URL which are then interpreted as $_GET variables.
I don't think it's a good idea to even try to make the pagination invisible. It's a similar problem to using frames or Flash - what if the user
wants to get to the second, third, or X page? If you kept your pagination invisible, that'd be impossible.
I think a URL like
http://www.mydomain.com/ExtraBitHere/2/ is perfectly acceptable.
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 11:04 am
by the moose
ok, so, lets say that I will go ahead and have the links displaying as:
Code: Select all
http://www.mydomain.com/ExtraBitHere/2
I get what your saying about users wanting to choose their page number etc etc.
Maybe you could help out with the .htaccess to do this, as sometimes it will just be:
Code: Select all
http://www.mydomain.com/Extra Bit Here
and sometimes it will have the number too (like above). the .htaccess I have at the moment is:
Code: Select all
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) page.php?bit=$1 [NC]
any ideas on how to get it to work?
I assume something like:
Code: Select all
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+) page.php?bit=$1&page=$2 [NC]
but that doesnt seem to work!!
Cheers
The Moose
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 11:15 am
by pickle
It might be easiest to have 2 rules in the .htaccess. One rule to handle the situation of there being no pagination identifier, and one rule for when there is.
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 11:28 am
by the moose
So, combine the two into something like:
Code: Select all
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) page.php?bit=$1 [NC]
RewriteRule ^([^/]+)/([^/]+) page.php?bit=$1&page=$2
Cheers
The Moose
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 11:40 am
by pickle
That's what I'd do. There's probably a way to do it in one expression, but I don't think it matters too much.
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 11:53 am
by the moose
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 11:59 am
by pickle
Put [NC] after your second rule. That should stop the rule from applying if the rule was accessed via a redirect.
I'm wondering why there is a redirect loop at all, as RewriteRule doesn't redirect the user, it's just used to serve up a file different than what was requested.
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 12:02 pm
by the moose
oh, and it screws up any images !!!
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 12:11 pm
by the moose
I dont know - a little bit weird!!
I added in the !-f and !-d lines between both rules too. I have [NC] after both rules.
That stopped the redirect loop. But screwed my images and didnt work!!
i think it is seeing the first variable to be Extra Bit Here/2 rather than splitting them, because of the first rule!
The Moose
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 12:15 pm
by pickle
Change your first expression to: ^([^/]+)/$ (note the new trailing slash. Also note the $ at the end. That signifies the pattern should match the entire request, rather than just matching from the beginning of the request, until a slash is found)
As it is, it's matching all requests. You want to restrict it to only match directories.
Comment out the second rule until the first rule works fine. Then move on to the second rule.
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 12:19 pm
by the moose
thing is that the first rule is working fine. wihtout throwing this paging nonsense into the mix, it is great!! I was shocked at this when i wrote it and it worked!! its only this damned second rule!
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 12:25 pm
by pickle
Hmmm, both your pattern and this pattern ^(.*)?/(.*)$ work fine when trying to match test/2.
Comment out the second rule, then in your page.php file, do a print_r($_SERVER). Maybe the requested URI isn't what you think?
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 12:37 pm
by the moose
Re: PHP $_POST variables (oh and DAMNED htaccess)
Posted: Fri Nov 28, 2008 12:54 pm
by pickle
If you require the pagination urls to be like:
http://www.mydomain.com/ExtraBitHere/2/, you can change your second rule to also end in a slash, thereby removing the chance it'll match files.
I'm not sure if .htaccess patterns have meta characters, but you might also be able to specify \d to only match numbers in the second set of parentheses.