问题
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