buckeye Posted June 11, 2019 Share Posted June 11, 2019 Hello, I am a regularly reader of your books, which have been very helpful and self-explanatory. However, I've ran into an issue I can't seem to figure out: I am trying to use the pagination from Chapter 10 and been successful in the past. Now, I need to use it a modularized site with mod_rewrite (adapted from your technique in PHP Advanced, Chapter 10). There are 52 records, which are consistent with my $display = 10; and $subcategoryShort = 'beds'; The links display as 1 2 3 4 5 Next (/our-furniture-test/beds/20/5/) My links appear to be correct, however, I get the following error: Not Found The requested URL /our-furniture-test/beds/20/5/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. I believe my queries are correct based on the number of records returned and the number of pages the links will show. However, I suspect my issue is with the coding of the links and/or the .htaccess file. I believe we need a different variable for each scenario, which is where the $one, $two and $three come from. The coding of the links is: <?php // Make the links to other pages, if necessary. if ($pages > 1) { // Add some spacing and start a paragraph: echo '<br><p>'; // Determine what page the script is on: $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous link: $one = $start - $display; if ($current_page != 1) { echo '<a href="/our-furniture-test/' . $subcategoryShort . '/' . $one . '/">Previous</a> '; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page && ($two = ($display * ($i - 1)))) { echo '<a href="/our-furniture-test/' . $subcategoryShort . '/' . $two . '/' . $pages . '/">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. // If it's not the last page, make a Next button: $three = $start + $display; if ($current_page != $pages) { echo '<a href="/our-furniture-test/' . $subcategoryShort . '/' . $three . '/' . $pages . '/">Next</a>'; } echo '</p>'; // Close the paragraph. } // End of links section. ?> And the .htaccess (assuming I needed a version for the three scenarios): RewriteRule (our-furniture-test)/([^/]*)/$ /index.php?p=$1&subcategoryShort=$2&one=$3 [L] RewriteRule (our-furniture-test)/([^/]*)/$ /index.php?p=$1&subcategoryShort=$2&two=$3&pages=$4 [L] RewriteRule (our-furniture-test)/([^/]*)/$ /index.php?p=$1&subcategoryShort=$2&three=$3&pages=$4 [L] Not sure where I am going wrong here. Any assistance would be appreciated! Link to comment Share on other sites More sharing options...
Larry Posted June 12, 2019 Share Posted June 12, 2019 If you're getting a 404, your PHP code is probably fine and it's the Apache configuration that's the problem. In other words, given this URL, Apache doesn't know what page to serve. It looks like your regular expressions are incorrect. You seem to be using the same matching pattern for all three conditions and that pattern doesn't match /our-furniture-test/beds/20/5/. Link to comment Share on other sites More sharing options...
Recommended Posts