douhuan6157 2017-12-01 09: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 09: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

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部