|a little help rewriting canonical pagination urls|
I've got a little php script i'm using for new content. But I did something a little wrong.
It does what it's suppose to, but it's also adding unnecessary, duplicate url's.
In .htaccess -
RewriteRule ^my-silly-new-content-([^.]+).html$ my-silly-new-content.html?page=$1
Basically what it does is add the first page which is :
and also the pages that increase whenever more content is added...such as :
etc, etc..so that's good. (whenever I have more than 10 items per page, I need it to go on the next page)
But, I just noticed the problem comes in, whenever anything is added after the
so that just typing in anything after that part, such as :
results in a new page as well, which displays the default content on
Basically, I just want the numeral system to keep going, while blocking any other extras from being indexed...to prevent duplicate content.
Thought I had the rewrite down flawlessly, but I guess not. :(
What flags are attached to your rule? It isn't directly relevant to the question, but I sure hope there's an [L]. Incidentally, the target should start with / (slash = root).
|whenever anything is added |
Yes, that's one of the long list of Problems You Don't Have To Worry About Unless They Happen. Here the fix is simple: just replace the all-encompassing
with a narrower
or (if you don't trust mod_rewrite's RegEx engine)
Also make sure that the php script itself returns a 404 for any non-numeric values of "page".
good enough, you should really have a Top Contributor tag next to your name. (Mods listening out there ? )
both instances worked whenever any letter / word was added into the mix. But numericals still passed through. example
still displayed a page, but idc. good enough. probably will only have 1000 max page total....before cutoff in the database.
The general flag / php coding that calls that part out :
$p = new pagination;
// Items per page
$p->perPage = 120;
// Pagination left from current
$p->paginationLeft = 3;
// Pagination right from current
$p->paginationRight = 3;
// Link href
// $p->path = '?page=%d'; // or $p->path = 'example/%d/';
$p->path = '/feeds/my-silly-new-content-%d.html';
// Paginaion appearance
'nav_prev' => '<a href="%s" class="prev"><span>prev</span></a>',
'nav_number_link' => '<a href="%s"><span>%d</span></a>',
'nav_next' => '<a href="%s" class="next"><span>next</span></a>'
$count = $db->get_one('SELECT count(*) as cnt FROM feeds');
// Items count
// Current page
|both instances worked whenever any letter / word was added into the mix. But numericals still passed through. |
This part is probably easier to do in php. Especially if the cutoff is some arbitary number: 2134 is valid, 2135 isn't.
You can certainly include a line in your RewriteRule that constrains the URL to some number of digits, like
Anything with too many digits would then bypass the rule and meet an ordinary server-generated 404.
You might also think about eliminating leading zeros if they don't have meaning. That's yet another of those Problems You Don't Have Until You... I've got one myself that says
RewriteRule ^dir/dir2/chap0+(\d+\.html) http://example.com/dir/dir2/chap$1 [R=301,L]
Your PHP script should be amended to return a 404 HEADER and to INCLUDE your 404 page when a URL request is invalid, such as a non-existent page number.
The RegEx pattern in the Rule can be constrained to ensure the URL ends with digits for the page numbers. I would use -1 for page one here for consistency.