doudou3716
2015-05-31 11:21
采纳率: 0%
浏览 70
已采纳

使用.htaccess和Apache重写两个参数的URL

I have below code in .htaccess:

Options -Indexes

RewriteEngine on

RewriteRule ^category/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ themes/tema_2/category.php?slug=$1&page=$2 [NC,L,QSA]

I have problem with second parameter "page"... When I do $_GET['slug'] i got something like this: fudbal/page/2 if my url is like this: http://exmpl.com/category/fudbal/page/2.

So $_GET['slug'] returns all after category/ like it's slug.

I need to achieve this: When I echo $_GET['slug'] to echo fudbal and When I echo $_GET['page'] to echo 2.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongxiandi8313 2015-05-31 17:27
    最佳回答

    You need to tweak your regex to fix your issue like this:

    Options -Indexes
    RewriteEngine on
    
    RewriteRule ^category/([^/]+)/?$ themes/tema_2/category.php?slug=$1 [NC,L,QSA]
    RewriteRule ^category/([^/]+)/page/(\d+)/?$ themes/tema_2/category.php?slug=$1&page=$2 [NC,L,QSA]
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题