[英]php how to read URL including # and / symbols
I have a website with a database of part numbers. 我有一个带有零件编号数据库的网站。 My manager wants to be able to type:
我的经理希望能够输入:
www.site.com/products/part#
and have thepage automatically take you to the relevant page. 并让该页面自动将您带到相关页面。
Right now I have it take the URL and mod-rewrite the page to: 现在,我拥有该网址并对其进行mod-rewrite页面:
www.site.com/search.php?sku=xxxx
And a php srcript will $_GET the sku and do the search, problem is, some part numbers have # and / symbols in them, eg: 而一个PHP脚本将$ _GET sku并进行搜索,问题是,某些零件号中带有#和/符号,例如:
www.site.com/products/VS816UT#ABA
I can get around any slashes with mod-rewrite, but the browsers strips the # symbol before the $_GET can see it. 我可以使用mod-rewrite解决任何斜杠,但是浏览器会在$ _GET看到它之前删除#符号。
Is there a way around that? 有办法解决吗?
Anything past the hash (the #
) isn't sent to the webserver. 哈希值之后的所有内容(
#
)均不会发送到网络服务器。
If you want to get around this, why not append the #ABA
with a slash: 如果要解决此问题,为什么不在
#ABA
加上斜杠:
www.site.com/products/VS816UT/ABA
And use mod_rewrite
to properly map it to your PHP file. 并使用
mod_rewrite
将其正确映射到您的PHP文件。
根据网络标准,#符号保留给浏览器中的定位标记。
There should be no trouble doing it, but what you want is a handler for /products/ that gets the trailing part of the url (frameworks like codeigniter are good at that). 这样做应该没有问题,但是您想要的是/ products /的处理程序,该处理程序获取url的结尾部分(像codeigniter这样的框架很擅长于此)。
You need a single page handler that dispatches based on as much (or as little) of the url as you need. 您需要一个单独的页面处理程序,该处理程序根据需要分配尽可能多(或尽可能少)的url。
Unfortunately, at least some browsers strip the # and everything after it. 不幸的是,至少某些浏览器会删除#及其后面的所有内容。 I did a test using a url with a# and monitored what the browser sent with tcpdump and got this:
我使用带有#的网址进行了测试,并监视了浏览器通过tcpdump发送的内容,并得到了以下信息:
Url: 网址:
http://127.0.0.1/onepage/products/zss#www?b=A#B
tcpdump o/p: tcpdump o / p:
GET /onepage/products/zss
Presumably, server-to-server is the only way this can work. 大概服务器到服务器是唯一可行的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.