.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
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