Support » Fixing WordPress » Ignoring &page in the URL

  • Hi,

    Is it possible to ignore &page in the URL to disable pagination for specific pages?

    I have a WordPress site which is integrating with a 3rd party PHP script which pulls info from their servers and that uses &page in the URL to return nested results, this breaks however as WordPress takes it as being page /2/, /3/, etc.

    I’ve tried to disable pagination on it’s own via functions.php however it still takes the &page from the URL and puts /2/ in the URL.


Viewing 7 replies - 1 through 7 (of 7 total)
  • Can you just modify the 3rd party PHP script to remove the “&page” from the URLs using either a regular expression with preg_replace or by parsing the query string and removing the “page” value?

    For example with preg_replace():

    $pattern = '/&page(\=[^&]*)?(?=&|$)|^page(\=[^&]*)?(&|$)/';
    $url = preg_replace($pattern, '', $url);

    I struggle with regular expressions myself, but that looks like it would replace page both if it is not the first parameter in the query string and if it is. You’ll have to modify it if the script is actually passing the HTML-encoded version of an ampersand instead of just the ampersand alone.


    Thanks for the help linux4me2.

    The &page value needs to be there. It’s not in all the URLs, only when you go to another page in the results it returns. It’ll probably help if I explain what it does.

    The website is for real estate searches and the third party company holds all the properties in their database. Instead of nesting inside an iframe they have provided some PHP which I’ve nested inside custom WP page templates. Everything works fine, except if you go to page 2 of the results it passes &page=2 in the URL and WordPress takes this and assumes /2/, and &page=2 is stripped from the URL – meaning you don’t actually get the second page of results, it stays on the first. Other arguments passed such as &maxPrice= and &city= work fine as you might expect.

    So what I was looking to do is work around that by getting WP to ignore &page on these custom page templates to allow the results to span various pages.

    Thanks again.

    I’m not certain I get it yet. Are you saying you are using SEO-friendly permalinks so your custom listings page URL looks something like:
    and when your users try to view page two of the listings the link that WordPress is creating looks something like:
    but you want it to be:
    If that’s correct, then one way is to alter the redirect you have in your .htaccess for permalinks so that when “listings” is in the URL it rewrites the query string so that the page parameter is sent like “page=2” the way you want. The other way would be to alter the PHP in the custom page templates so it interprets the URL correctly.

    For the former, you’re going to need to post the URLs the way they are, and the way they should look, along with the current redirects in your .htaccess file so that someone can help you come up with the correct syntax.

    For the latter, we’re going to have to see the code block that receives the URL in order to suggest how to alter it.


    Your first example is exactly correct. In this case it works like;

    Listings page: – shows everything.

    Page 2 Target URL:

    Page 2 WP generated URL:

    I’ve substituted some values there such as the api key.

    So we would basically need to create a .htaccess rule which only applies when /properties/ is part of the URL?


    If I’m following you, yes, that would mean WordPress would still be generating the URLs with the “/2” in there, but when the user clicks on them, mod_rewrite would get hold of it and change it from this:
    to this:
    which is what the URL would be coming into your script, as if the user had pasted the second one into the address bar of their browser. Would that work?

    If so, what you’d essentially be doing is having mod_rewrite take what looks like a subdirectory and changing it into a query string parameter called “page.” I know mod_rewrite can do that, but it’s beyond my limited abilities with mod_rewrite.

    I think what you’re going to want is something like this integrated with your current conditions/rules for your permalinks:

    RewriteEngine On
    RewriteRule ^(?properties/)(.*)$ properties/?page=$1 [QSA,L]

    but I’m not sure I have the “properties” part right. What that’s saying (I hope) is that if “properties” is in the path, add the name of the subfolder on as the value of the “page” parameter, then append the rest of the query string (that’s what the “QSA” is for).

    You’ll have to try it and see if your entire site explodes and let me know. If it doesn’t work, you might try posting over on Stack Overflow in the mod_rewrite section. If you give them the current URL and the intended URL along with this Forrest Gump attempt, I think they’ll help you. Either way, please post back here because I’d like to know what works out. : )


    Many thanks for all your efforts. I’ll give it a try after the coffee sets in and I’m awake! Will post back with the results 🙂


    The suppliers of the 3rd party stuff have provided this function which works,

    add_filter('request', 'on_request_na');
    function on_request_na($vars)
      return $vars;

    I’m going to continue to look at the rewrite rule however, so I can control this for just the Property pages rather than turning off pagination site wide.


Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Ignoring &page in the URL’ is closed to new replies.