douhuan6157 2017-12-01 17:05
浏览 34
已采纳

无法将路径信息移动到htaccess中的查询字符串

I would like to rewrite www.mysite.com/a/b/slug to www.mysite.com/a/b/index.php?id=slug.

I am trying to capture the last segment of the path i.e. slug and use it in the query string -- similar to this example.

So I have the following lines in my .htaccess sitting in my public_html folder:

RewriteEngine on
RewriteRule ^a/b/([^/]+) a/b/index.php?id=$1 [L]

In my a/b/index.php, when I go to www.site.com/a/b/slug, $_GET['id'] returns index.php opposed to slug. I am not sure why.

How can I capture the last segment and use it in the query string?

  • 写回答

1条回答 默认 最新

  • doume5227 2017-12-01 17:24
    关注

    You need to add rewrite conditions in your .htaccess - at the moment, it is attempting to rewrite /a/b/index.php as well!

    Try adding RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败