Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 369955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:58:16+00:00 2026-05-12T13:58:16+00:00

I am stuck now, here below is a snip from my paging code, this

  • 0

I am stuck now, here below is a snip from my paging code, this is the part the builds the URL for the paging links, it worked really great until now because now I am changing my whole site to use mod-rewrite so before a page would look like this

http://localhost/?p=mail.inbox&page=2

and now I want it to be like this..I already have the regex to do it but I need to change the way my paging builds links to the new URL’s correctly

http://localhost/mail/inbox/page/2

here is the code that makes the OLD links, any help or ideas on how I can use for new links?

the catch is the way it works now is it can determine if other variables exist in the URL and if it see’s them it will make sure it keeps them in the URL it makes when making new page links, for example is ?p=test&userid=2&color=green&page=3 it would make sure to keep all the extra stuff in the new url it makes and just increase or decrease the page number

$url_string = "?";
foreach ($_GET as $k => $v) {
    if ($k != "page") { // <-- the key you don't want, ie "page"
        if ($url_string != "?") {
            $url_string .= "&"; // Prepend ampersands nicely
        }
        $url_string .= $k . "=" . $v;
    }
}
$selfurl = $url_string . '&page=';
$page = $_GET['page'];
if ($page) {
    $start = ($page - 1) * $items_per_page;
}
else {
    $start = 0;
}
if ($page == 0) {
    $page = 1; //if no page var is given, default to 1.
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:58:16+00:00Added an answer on May 12, 2026 at 1:58 pm

    This will do the trick

    $uri = $_SERVER['REQUEST_URI'];
    $uri = preg_replace('#page/\d+/*#', '', $uri); // remove page from uri
    $uri = preg_replace('#/$#', '', $uri); // remove trailing slash
    
    $selfurl = $uri . '/page/';
    $page = $_GET['page'];
    if ($page) {
      $start = ($page - 1) * $items_per_page;
    } else {
      $start = 0;
    }
    if ($page == 0) {
      $page = 1;
    }
    

    What the code is doing here is removing the /page/2 part from the uri if it exists and then you can modify the code as you want.
    You mentioned that the code works if /page/1 part is not in the URI so removing that part if it exists should work too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 433k
  • Answers 433k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer rownum is a pseudocolumn in a result set. It is… May 15, 2026 at 2:57 pm
  • Editorial Team
    Editorial Team added an answer Some of the PortableApps.com applications (specifically Inkscape portable, but there… May 15, 2026 at 2:57 pm
  • Editorial Team
    Editorial Team added an answer Yeah, not sure where that text came from. I'm a… May 15, 2026 at 2:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.