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

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

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加