doutan1875 2019-07-16 20:17
浏览 203

如何使用htaccess为空间创建RewriteRule

I use htaccess for make mu URL clean. My original ULR is http://localhost/bookStore/single_book.php?name=This%20is%20book%20no%204

i use php urlencode() function to make this

http://localhost/bookStore/single_book.php?name=This+is+book+no+4

but now i want to make this like:

http://localhost/bookStore/single_book/This+is+book+no+4

using htaccess

RewriteRule ^single_book/([0-9a-zA-Z_-]+) single_book.php?name=$2 [NC,L]

RewriteRule not working

  • 写回答

1条回答 默认 最新

  • doubi9615 2019-07-16 20:42
    关注
    RewriteCond %{QUERY_STRING} ^name=(.+)
    RewriteRule ^(bookStore/single_book)(\.php)$ $1/%1?
    

    This matches if name is in the query string and if the name is the only portion of the query string.

    I tested on https://htaccess.madewithlove.be/

    And for playing with the regex, i used https://regexr.com/

    The trailing ? in the RewriteRule removes the query string.

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题