dskld5423 2015-11-20 04:05
浏览 43
已采纳

如何在htaccess RewriteRule正则表达式中允许撇号?

I'm retrieving menus from database and some of them have an apostrophe - ' - in their names. In a part of my code I have to compare the name from the database with the url, but it fails when the url has an apostrophe.

For example:

when I get the name from the db I get it as it is: foo's

but from the url, even if the url is web.com?menu=foo's when I do this:

$menu = urldecode($_GET['menu']);

I get only foo

this is my htaccess Rewrite

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^explore/([0-9a-zA-Z\ ]+) renderpage.php?menu=$1 [L]

I've tried all the possible combination in my php, it's not that, it is this RewriteRule that doesn't allow apostrophe, I've also tried ([0-9a-zA-Z\ ']+) in my regex and ([0-9a-zA-Z\ \']+) but to no avail.

  • 写回答

1条回答 默认 最新

  • duanhe6718 2015-11-20 04:24
    关注

    I think the issue is in the position of apostrophe Try this:

    ([0-9a-zA-Z'\]+)
    

    or

    ([0-9a-zA-Z']+)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题