通过htaccess和root分页获得价值

时间:2015-07-10 05:26:37

标签: php regex .htaccess mod-rewrite pagination

此网址

example.com/videos/load.php?cat=video-category

会变成

example.com/videos/video-category

此外,还有分页&限制网址

example.com/videos/load.php?cat=video-category&p=2&limit=20

它会变成

example.com/videos/video-category?p=2&limit=20

(此链接也有效)

example.com/videos/video-category?p=2
example.com/videos/video-category?limit=20

此外,还有另一个根网址

example.com/videos/load.php?cat=video-category&name=video-name

它会变成

example.com/videos/video-category/video-name

此外,还有分页&限制网址

example.com/videos/load.php?cat=video-category&name=video-name&p=2&limit=20

它会变成

example.com/videos/video-category/video-name?p=2&limit=20

(此链接也有效)

example.com/videos/video-category/video-name?p=2
example.com/videos/video-category/video-name?limit=20

这是我的htaccess(进入videos文件夹)

Options +FollowSymLinks

RewriteEngine on
RewriteBase /videos/

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L]

RewriteCond %{THE_REQUEST} \ /+videos/load\.php\?cat=([^&\ ]+)&?([^\ ]*)
RewriteRule ^ %1?%2 [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ load.php?cat=$1 [L,QSA]

如何做到这一点..请帮帮我..谢谢..

1 个答案:

答案 0 :(得分:1)

这样做:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /videos/

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L]

RewriteCond %{THE_REQUEST} \s/+videos/load\.php\?cat=([^&\s]+)&name=([^&\s]+)&?(\S*)
RewriteRule ^ %1/%2?%3 [L,R=302]

RewriteCond %{THE_REQUEST} \s/+videos/load\.php\?cat=([^&\s]+)&?(\S*)
RewriteRule ^ %1?%2 [L,R=302]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ load.php?cat=$1&name=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ load.php?cat=$1 [L,QSA]