简体   繁体   中英

.htaccess for pagination to redirect example.com/page/page_id

htaccess code to redirect page without have to call extension. i'm trying to implement pagination without using ?page=2 or ?page=3 instead i try to use example.com/page/2 etc with uri.

for example i have example.com/page/2 , i would like to redirect it to page.php

but i also want to be able to call all of the file without php extension

here is my .htaccess

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)/?$ $1.php [L]

it works but when i try to call example.com/page/2 it says Object not found!

here is my page.php

<?php 
$uri = $_SERVER["REQUEST_URI"];
$uri_array = explode("/", $uri);
echo $uri_array[3];

im trying to get the value from page_id for my pagination

i see that you're in a wrong way as you make your own page.php for simply doing it for example.com/page/2 instead you should do this in your index.php example.com/index.php?page=page_id so you will be able to rewrite it as example.com/page/page_id

it's common mistake for someone who new to pagination to create somethings like that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM