Ari*_*ona 5 javascript php browser ajax mod-rewrite
假设我有以下链接:
www.blahblah.com/#!?page=index
Run Code Online (Sandbox Code Playgroud)
如何将其转换为以下之一:
www.blahblah.com/#!/index (这个应该用mod_rewrite制作)www.blahblah.com/ajax/index (仍然是mod_rewrite,但#!替换为ajax)www.blahblah.com/index (该页面将加载像facebook这样的AJAX,但#!将被隐藏)任何人都可以举例说明上述每个问题吗?
非常感谢!
哈希 ( #) 之后的任何内容都不会发送到服务器,因此您无法在服务器端读取它。但是,您可以使用 JavaScript 重定向用户。您要查找的信息将存储在变量 中window.location.hash。
在页面加载时,您可以执行以下操作:
hashString = window.location.hash.substring(8);
window.location = 'http://www.blahblah.com/'+hashString;
Run Code Online (Sandbox Code Playgroud)
我们使用substring删除前八个字符 ( #!?page=),因此我们将留下index。