通过htaccess和分页获得价值

时间:2014-04-19 16:19:07

标签: .htaccess mod-rewrite

此网址

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

会变成

example.com/videos/video-category

此外,还有分页网址

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

它会变成

example.com/videos/video-category/page/2

我试图这样做..但它不起作用。
这是我的htaccess(进入videos文件夹)

Options +FollowSymLinks
RewriteEngine On
RewriteBase /videos/

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]

RewriteRule ^(\w+/+/)page/?$ $1 [R=301,L]

RewriteRule ^(\w+)(?:/[^/]+)?/?$ load.php?cat=$1 [L,QSA]

RewriteRule ^(\w+)/[^/]+/([0-9]+)/?$ load.php?cat=$1&p=$2 [L,QSA]

1 个答案:

答案 0 :(得分:2)

将此代码放入htaccess。
这应该工作

Options +FollowSymLinks

RewriteEngine on
RewriteBase /videos/

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

RewriteRule ^([^/]+)/?$ load.php?cat=$1 [L,QSA]
RewriteRule ^([^/]+)/page/?$ $1 [R=301,L]
RewriteRule ^([^/]+)/page/([1-9][0-9]*)$ load.php?cat=$1&p=$2 [L,QSA]