简体   繁体   中英

URL rewriting with pagination not working .htaccess?

I have this following url index.php?page=1 i want it to be index.php/page/1 .

so far i have this

RewriteEngine on

RewriteRule ^page/([^/]*)$ index.php?page=$1 [L]

and my pagination link looks like this:

$numbers.='<li><a class="active" href="?page='.$i.'">'.$i.'</a></span></li>'

If I use that it doesn't rewrite the Url.

and if i change my pagination to

$numbers.='<li><a class="active" href="?page/'.$i.'">'.$i.'</a></span></li>'

pagination stopped working and my result displays weirdly. Any idea why is this happening ?

You can use following RewriteRule:

RewriteRule ^index.php/page/([0-9]+)$ index.php?page=$1 [L]

And links:

<li><a class="active" href="/index.php/page/'.$i.'">'.$i.'</a></li>

Or exclude index.php/ from both if you dont want it in our links.

ok, if you really need your pagination link look like "?page/2" you can delete the rewrite rule and use following instead of $_GET['page'] : intval(explode("?page/", $_SERVER["REQUEST_URI"])[1]) - this basically splits URL by ?page/ and returns anything behind it as integrer - works in PHP >= 5.4. btw. this is VERY bad implementation of pagination link structure... but it will work

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