Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess Mod重写所有分页的一般规则?_.htaccess_Mod Rewrite_Pagination - Fatal编程技术网

.htaccess Mod重写所有分页的一般规则?

.htaccess Mod重写所有分页的一般规则?,.htaccess,mod-rewrite,pagination,.htaccess,Mod Rewrite,Pagination,这样的事情可以做吗?无论在哪个页面或目录下显示page=$1,它都将被重写/重定向到/$1 例如: file.php/1将是file.php?page=1 dir/file/2将是dir/file?page=2 dir/file.php?name=something/3将是dir/file.php?name=something&page=3 以下是我目前掌握的情况: RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+ RewriteCond

这样的事情可以做吗?无论在哪个页面或目录下显示
page=$1
,它都将被重写/重定向到
/$1

例如:

file.php/1将是file.php?page=1

dir/file/2将是dir/file?page=2

dir/file.php?name=something/3将是dir/file.php?name=something&page=3

以下是我目前掌握的情况:

RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteCond %{QUERY_STRING} ^&page=([0-9-]+)/?$ 
RewriteRule ^(.+)\.php$ $1/%2 [R=301,L]
RewriteRule ^(.*)$ $1.php/$2

要覆盖以/123结尾的URI路径,我们可以使用以下规则:

RewriteRule ^(.+)/([0-9]+)$ /$1?page=$2 [QSA,L,R]
RewriteCond %{QUERY_STRING} (.*)/([0-9]+)$
RewriteRule ^(.+)$ /$1?%1&page=%2 [L]
因此:

  • file.php/1将是file.php?page=1
  • dir/file/2将是dir/file?page=2
  • 请注意,这也将包括:dir/file/3?foo=bar将是dir/file?page=3&foo=bar
为了涵盖附加在实际查询字符串末尾的/123,我们可以使用以下规则:

RewriteRule ^(.+)/([0-9]+)$ /$1?page=$2 [QSA,L,R]
RewriteCond %{QUERY_STRING} (.*)/([0-9]+)$
RewriteRule ^(.+)$ /$1?%1&page=%2 [L]
因此:

  • dir/file.php?name=something/3将是dir/file.php?name=something&page=3