Let's say I have the following link:
假设我有以下链接:
www.blahblah.com/#!?page=index
How can I convert it to one of the following:
如何将其转换为以下之一:
-
www.blahblah.com/#!/index
(this one should be made with mod_rewrite) - www.blahblah.com/#!/index(这个应该用mod_rewrite制作)
-
www.blahblah.com/ajax/index
(still mod_rewrite, but #! replaced with ajax) - www.blahblah.com/ajax/index(仍然是mod_rewrite,但#!替换为ajax)
-
www.blahblah.com/index
(the page will load with AJAX like facebook, but #! will be hidden) - www.blahblah.com/index(该页面将加载像facebook这样的AJAX,但#!将被隐藏)
Can anyone give me examples of each of the questions above?
任何人都可以举例说明上述每个问题吗?
Thanks alot!
非常感谢!
4 个解决方案
#1
3
Anything after the hash (#
) isn't sent to the server, so you cannot read it server-side. You can, however, redirect the user using JavaScript. The information you're looking for will be stored in the variable window.location.hash
.
散列(#)之后的任何内容都不会发送到服务器,因此您无法在服务器端读取它。但是,您可以使用JavaScript重定向用户。您要查找的信息将存储在变量window.location.hash中。
On page load, you can do something like the following:
在页面加载时,您可以执行以下操作:
hashString = window.location.hash.substring(8);
window.location = 'http://www.blahblah.com/'+hashString;
We're using substring
to remove the first eight characters (#!?page=
), so we'll be left with index
.
我们使用子字符串来删除前八个字符(#!? page =),因此我们将留下索引。
#2
1
Module rewrite only changes what the server sees. Module rewrite can't, change what the local browser sees, which is where the js is being run.
模块重写仅更改服务器看到的内容。模块重写不能,改变本地浏览器看到的内容,这是运行js的地方。
The way Facebook load, is through requesting the contents of the new page, then it updates the window URL instead of having to re-load everything. This is done, so If an item needs to be shared or linked the link is all up to date with what they're actually viewing, so when the page gets a fresh re-load, the browser loads the actual full php page, requested from the server.
Facebook加载的方式是通过请求新页面的内容,然后更新窗口URL而不必重新加载所有内容。这样就完成了,所以如果一个项目需要被共享或链接,那么链接都是他们实际查看的内容的最新版本,所以当页面重新加载时,浏览器会加载实际的完整php页面,请求从服务器。
#3
1
The hidden # in a ajax page loading strategy is done by HTML 5 pushState.
ajax页面加载策略中隐藏的#由HTML 5 pushState完成。
#4
0
In javascript you can use window.location.hash
for this.
在javascript中,您可以使用window.location.hash。
#1
3
Anything after the hash (#
) isn't sent to the server, so you cannot read it server-side. You can, however, redirect the user using JavaScript. The information you're looking for will be stored in the variable window.location.hash
.
散列(#)之后的任何内容都不会发送到服务器,因此您无法在服务器端读取它。但是,您可以使用JavaScript重定向用户。您要查找的信息将存储在变量window.location.hash中。
On page load, you can do something like the following:
在页面加载时,您可以执行以下操作:
hashString = window.location.hash.substring(8);
window.location = 'http://www.blahblah.com/'+hashString;
We're using substring
to remove the first eight characters (#!?page=
), so we'll be left with index
.
我们使用子字符串来删除前八个字符(#!? page =),因此我们将留下索引。
#2
1
Module rewrite only changes what the server sees. Module rewrite can't, change what the local browser sees, which is where the js is being run.
模块重写仅更改服务器看到的内容。模块重写不能,改变本地浏览器看到的内容,这是运行js的地方。
The way Facebook load, is through requesting the contents of the new page, then it updates the window URL instead of having to re-load everything. This is done, so If an item needs to be shared or linked the link is all up to date with what they're actually viewing, so when the page gets a fresh re-load, the browser loads the actual full php page, requested from the server.
Facebook加载的方式是通过请求新页面的内容,然后更新窗口URL而不必重新加载所有内容。这样就完成了,所以如果一个项目需要被共享或链接,那么链接都是他们实际查看的内容的最新版本,所以当页面重新加载时,浏览器会加载实际的完整php页面,请求从服务器。
#3
1
The hidden # in a ajax page loading strategy is done by HTML 5 pushState.
ajax页面加载策略中隐藏的#由HTML 5 pushState完成。
#4
0
In javascript you can use window.location.hash
for this.
在javascript中,您可以使用window.location.hash。