erme Posted August 5, 2009 Share Posted August 5, 2009 Hi, I have the following code (not written by me) if($_GET) { $args = explode("&",$_SERVER['QUERY_STRING']); foreach($args as $arg) { $keyval = explode("=",$arg); if($keyval[0] != "offset" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg; } } and have this in the htaccess: RewriteRule ^index/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?offset=$1&ipp=$2&county=$3& [L,NC] to rewrite the horrible URL. All works great, however when ever I run the script it outputs &county= in the URL, where as I want it to output just the county name. In otherwords, I want: http://www.site.com/index/5/10/devon/ and not: http://www.site.com/index/5/10&county=devon/ Sorry if I'm not explaining myself very well. Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Bricktop Posted August 5, 2009 Share Posted August 5, 2009 Hi erme, You have an extra & on the end of your rewrite rule which isn't needed. Give it a go without that. Quote Link to comment Share on other sites More sharing options...
erme Posted August 5, 2009 Author Share Posted August 5, 2009 Hi Bricktop, Unfortunately the problem persists. I don't think its an issue with the htaccess, but rather the PHP. I'm very new to PHP and, as I said, didn't write the code. The code is from a paginator and is where the problem happens when flicking between pages. Quote Link to comment Share on other sites More sharing options...
erme Posted August 5, 2009 Author Share Posted August 5, 2009 Example: http://s239382210.websitehome.co.uk/ First select a county eg devon then a page number at the bottom. Notice what happens to the url. http://s239382210.websitehome.co.uk/index/2/10&county=devon/ If you change &county=devon to /devon it still works. Quote Link to comment Share on other sites More sharing options...
Bricktop Posted August 5, 2009 Share Posted August 5, 2009 Hi erme, I think it's because the URL's from the menu are different to those of the Pagination. For example, if I click "devon" from the menu at the top the URL is: http://s239382210.websitehome.co.uk/index/devon However, now I'm on the "devon" page, if I click the pagination menu to go to page 2 I get the URL of: http://s239382210.websitehome.co.uk/index/2/10&county=devon/ I would expect a URL of: http://s239382210.websitehome.co.uk/index/devon/2/10 Otherwise, can you add the following to your code (inside the foreach loop): echo $_SERVER['QUERY_STRING']; echo $keyval; That way we can see what the PHP is outputting to the browser. Quote Link to comment Share on other sites More sharing options...
erme Posted August 5, 2009 Author Share Posted August 5, 2009 Have added Quote Link to comment Share on other sites More sharing options...
Bricktop Posted August 5, 2009 Share Posted August 5, 2009 OK, $keyval is outputting "county=devon". For the Mod_rewrite to work properly it needs to just output "devon". Could you remove the two echo commands you just added and add: echo $arg; Thanks Quote Link to comment Share on other sites More sharing options...
erme Posted August 5, 2009 Author Share Posted August 5, 2009 Thanks for your help. Have added that now. Quote Link to comment Share on other sites More sharing options...
Bricktop Posted August 5, 2009 Share Posted August 5, 2009 OK, $arg is also outputting county=devon. This is where the problem lies, but are you able to post more of the pagination code? Would be nice to see the code which actually generates the links. Otherwise, try changing your code to: if($_GET) { $args = explode("&",$_SERVER['QUERY_STRING']); foreach($args as $arg) { $keyval = explode("=",$arg); $arg = strrpos($arg,'='); $arg = substr($arg,$i+1); if($keyval[0] != "offset" And $keyval[0] != "ipp") $this->querystring .= $arg; } } Here I'm taking the $arg variable, and outputting just the bit after the = using the $arg = strrpos($arg,'='); and $arg = substr($arg,$i+1); lines of code. Make sure you take a backup before doing this but without seeing the rest of the code hard to see exactly where this is fallingover. Thanks Quote Link to comment Share on other sites More sharing options...
erme Posted August 5, 2009 Author Share Posted August 5, 2009 Bricktop, I have sent you a message. Thanks Quote Link to comment Share on other sites More sharing options...
Bricktop Posted August 6, 2009 Share Posted August 6, 2009 Anyone else able to help erme with this? It's beyond me now - sorry erme but I tried my best Quote Link to comment Share on other sites More sharing options...
erme Posted August 6, 2009 Author Share Posted August 6, 2009 Thanks for trying Bricktop Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 underneath $keyval = explode("=",$arg); paste this echo "_SERVER['QUERY_STRING']: <br /><br />".nl2br(str_replace(' ',' ',print_r($_SERVER['QUERY_STRING'],true)))"<br /><br />"; echo "Arg: <br /><br />".nl2br(str_replace(' ',' ',print_r($arg,true)))"<br /><br />"; echo "Keyval: <br /><br />".nl2br(str_replace(' ',' ',print_r($keyval,true)))"<br /><br />"; so we can see the contents of $keyval and the others... (lol i was being a retard ) Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 oops... put dots between )" echo "_SERVER['QUERY_STRING']: <br /><br />".nl2br(str_replace(' ',' ',print_r($_SERVER['QUERY_STRING'],true)))."<br /><br />"; echo "Arg: <br /><br />".nl2br(str_replace(' ',' ',print_r($arg,true)))."<br /><br />"; echo "Keyval: <br /><br />".nl2br(str_replace(' ',' ',print_r($keyval,true)))."<br /><br />"; ---------- _SERVER['QUERY_STRING']: offset=4&ipp=10&county=dorset Arg: offset=4 Arg: ipp=10 Arg: county=dorset Keyval: Array ( [0] => county [1] => dorset ) String: &county=dorset I got my script to output that, so it's giving the right value.. post the querystring function Quote Link to comment Share on other sites More sharing options...
erme Posted August 6, 2009 Author Share Posted August 6, 2009 Thanks Mardoxx, have added: http://s239382210.websitehome.co.uk/ Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 I did this: <?php echo "<b>_SERVER['QUERY_STRING']: </b><br /><br />".nl2br(str_replace(' ',' ',print_r($_SERVER['QUERY_STRING'],true)))."<br /><br />"; $args = explode("&",$_SERVER['QUERY_STRING']); foreach($args as $arg) { $keyval = explode("=",$arg); echo "<b>Arg: </b><br /><br />".nl2br(str_replace(' ',' ',print_r($arg,true)))."<br /><br />"; if($keyval[0] != "offset" And $keyval[0] != "ipp") $thisquerystring .= "&" . $arg; } echo "<b>Keyval: </b><br /><br />".nl2br(str_replace(' ',' ',print_r($keyval,true)))."<br /><br />"; echo "<b>Thisquerystring: </b><br /><br />".nl2br(str_replace(' ',' ',print_r($thisquerystring,true)))."<br /><br />"; so the problem probably lies with the querystring function Quote Link to comment Share on other sites More sharing options...
erme Posted August 6, 2009 Author Share Posted August 6, 2009 Here's the Paginator code http://s239382210.websitehome.co.uk/Paginator.class.phps Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 actually no, I'm thinking it's to do with yeah the mod_rewrite because it's adding the &country=devon to the URL but it's just not rewriting it just did some research http://www.daniweb.com/forums/thread7826.html# try this as your mod_rewrite rule: ^index/([^/]+)/?([^/]+)/?([^/]+)/?$ Quote Link to comment Share on other sites More sharing options...
erme Posted August 6, 2009 Author Share Posted August 6, 2009 Added but still no luck Starting to be more hassle then its worth! Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 try this: change if($keyval[0] != "offset" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg; to if($keyval[0] != "offset" And $keyval[0] != "ipp") $this->querystring .= "/" . $keyval[1]; Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 it's an awful hack - but it works for now... I'm p sure the problem lies with this: RewriteRule ^index/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?offset=$1&ipp=$2&county=$3& [L,NC] Quote Link to comment Share on other sites More sharing options...
erme Posted August 6, 2009 Author Share Posted August 6, 2009 OOOoooOOoo!! I think you may have cracked it!!!! Take a look: http://s239382210.websitehome.co.uk/ Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 if ($this->showAll == true) $this->return .= ($_GET['offset'] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$WEBSITE/1/All$this->querystring/\">All</a> \n"; needs to be changed you need to strip out the .php from $WEBSITE //edit actually I'm not quite sure where it's coming from :S Quote Link to comment Share on other sites More sharing options...
erme Posted August 6, 2009 Author Share Posted August 6, 2009 Yeah saw that .. will get right onto it .. can now make a start on getting the other functions to work too Quote Link to comment Share on other sites More sharing options...
erme Posted August 6, 2009 Author Share Posted August 6, 2009 Thanks Mardoxx, much appreciated! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.