doudou3716 2015-05-31 11:21 采纳率: 100%
浏览 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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件