简体   繁体   English

.htaccess用于分页以重定向example.com/page/page_id

[英].htaccess for pagination to redirect example.com/page/page_id

htaccess code to redirect page without have to call extension. htaccess代码可以重定向页面,而无需调用扩展程序。 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. 我尝试不使用?page = 2或?page = 3来实现分页,而是尝试将uri与example.com/page/2等一起使用。

for example i have example.com/page/2 , i would like to redirect it to page.php 例如我有example.com/page/2,我想将其重定向到page.php

but i also want to be able to call all of the file without php extension 但我也希望能够在没有php扩展名的情况下调用所有文件

here is my .htaccess 这是我的.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! 它可以工作,但是当我尝试调用example.com/page/2时,它说找不到对象!

here is my page.php 这是我的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 我试图从page_id获取我的分页的值

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 我看到您在制作自己的page.php时出错了,因为仅仅这样做了,例如example.com/page/2,而应该在index.php example.com/index.php?page= page_id,因此您可以将其重写为example.com/page/page_id

it's common mistake for someone who new to pagination to create somethings like that 对于刚接触分页的人来说,创建这样的东西是常见的错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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