G
G
Genri_Rus2019-03-03 22:30:54
htaccess
Genri_Rus, 2019-03-03 22:30:54

How to add a slash at the end of pagination?

Good day to all!
There was the following problem in pagination, there is the following code structure:
In .htaccess

RewriteRule ^([0-9]+)_(.*)/$ list.php?cat=$1
RewriteRule ^([0-9]+)_(.*)/([0-9]+)/$ list.php?cat=$1&page=$3

jquery
$('body').on('click', '.pagination a', function(){
  var ajxData = $('#ajaxLoading');
  page = $(this).data('page');
    $.ajax({
      type: 'POST',
      url: page+'/page/',
      success: function(data) {
        var content = $(data).find('#ajaxData').html();
        $('#ajaxData').html(content);
      }
    });
  });

In .htaccess
RewriteRule ^([0-9]+)_(.*)/([0-9]+)/$ list.php?cat=$1&page=$3

An interesting pattern arose, if I do this: url: page + '/page/', then pagination does not work
And if like this url: page, then it works
In .htaccess
RewriteRule ^([0-9]+)_(.*)/([0-9]+)$ list.php?cat=$1&page=$3

The page variable is responsible for pages in this format:
$page = (isset($_GET["page"]) AND intval($_GET["page"]) >= 1) ? intval($_GET["page"]) : 1;

Does anyone know why pagination works without a slash, but doesn't work with a slash at the end?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2019-03-04
@Genri_Rus

RewriteRule ^([0-9]+)_(.*)/$ list.php?cat=$1
RewriteRule ^([0-9]+)_(.*)/([0-9]+)/$ list.php?cat=$1&page=$3

(.*)means any number of any characters.
^([0-9]+)_(.*)/$matches 123_text/and 123_text/345/.
The rules are checked sequentially and need to be swapped.
RewriteRule ^([0-9]+)_(.*)/([0-9]+)/$ list.php?cat=$1&page=$3
RewriteRule ^([0-9]+)_(.*)/$ list.php?cat=$1

V
Viktor Taran, 2019-03-04
@shambler81

RewriteRule ^([0-9]{1,})_(.+[^/])/([0-9]{1,})$ list.php\?cat\=$1&page\=$3

From zero to nine 1 time or more, BUT no slash to slash;)
and do not forget to escape special characters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question