Jump to content

[SOLVED] QUERY_STRING mod_rewrite problem


erme

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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 :P)

 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.