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. Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/ 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. Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-891506 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. Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-891513 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. Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-891520 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. Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-891550 Share on other sites More sharing options...
erme Posted August 5, 2009 Author Share Posted August 5, 2009 Have added Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-891557 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 Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-891582 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. Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-891583 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 Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-891587 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 Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-891634 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 Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-891960 Share on other sites More sharing options...
erme Posted August 6, 2009 Author Share Posted August 6, 2009 Thanks for trying Bricktop Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-891997 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 ) Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892004 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 Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892015 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/ Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892017 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 Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892020 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 Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892022 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/([^/]+)/?([^/]+)/?([^/]+)/?$ Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892025 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! Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892030 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]; Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892033 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] Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892034 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/ Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892036 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 Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892038 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 Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892040 Share on other sites More sharing options...
erme Posted August 6, 2009 Author Share Posted August 6, 2009 Thanks Mardoxx, much appreciated! Link to comment https://forums.phpfreaks.com/topic/168964-solved-query_string-mod_rewrite-problem/#findComment-892050 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.