how to match # character in a url in nginx through location directive

喜你入骨 提交于 2021-02-16 21:37:00

问题


How do I match a # character in a url using location directive? I understand that we can use regex(PCRE), but their docs say that :

The location directive only tries to match from the first / after the hostname, to just before the first ? or #. (Within that range, it matches the unescaped url.)"

In short, How to match "example.com/#123456" using

location ~ [someregex] {
   return 200 "matched";
}

or with any other alternative


回答1:


Simple answer, you can't actually, because that part is never sent to the server to begin with, the only way to process this is to use Javascript, using location.hash




回答2:


You can't because the ID hash isn't actually sent to the server, you might want to use GET variables like example.com?p=1234 if you intend to direct to a certain page or use location.hash if you wish to direct to a location on the page (which is its intended use)

Good luck!



来源:https://stackoverflow.com/questions/19704468/how-to-match-character-in-a-url-in-nginx-through-location-directive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!