【发布时间】:2012-10-10 07:12:52
【问题描述】:
我正在做一个带有分页的过滤系统,但我在尝试根据当前 URL 使用 Javascript 重定向时遇到了麻烦。
我可以拥有这种类型的 URL,其中最后一个数字是过滤器:
http://localhost/posts/yourPosts/1
http://localhost/posts/subscriptions/3
并且在每种类型中,第2页都会以这种方式显示:
http://localhost/posts/yourPosts/1/page:2?url=posts%2FyourPosts
http://localhost/posts/subscriptions/3/page:2?url=posts%2FSubscriptions
我目前正在使用:
window.location.href = currentURL + '/' + encodeURI($(this).val());
其中 $(this).val 是要使用的过滤器的编号。
问题是当我在这个 URL 中时它运行良好:
http://localhost/posts/yourPosts/
http://localhost/posts/subscriptions/
但是当我在第二页并且我想显示过滤器编号 3(比如说,汽车而不是动物)时,它没有。它显示了这一点:
http://localhost/posts/subscriptions/2/page:2?url=posts%2FyourPosts/3
而不是这个:
http://localhost/posts/subscriptions/3
有没有简单的处理URL的方法来解决这类问题?
我也不能使用绝对路径,因为 URL 并不完全相同。那么...有什么办法可以更改 URL 的最后一个 PATH 吗?
【问题讨论】:
标签: javascript url url-rewriting path