1

I'm working on a site that has a basic slider with 4 slides that go left and right that only shows 1 slide centered in the page. All the slides' content are loaded on a single page each within it's own div.

<div id="slider-box">
    <div class="slide">HTML and bg image</div>
    <div class="slide">HTML and bg image</div>
    <div class="slide">HTML and bg image</div>
    <div class="slide">HTML and bg image</div>
</div>

Nothing fancy. Also each slide is associated with a link:

<a href="/gallery">Gallery</a>
<a href="/links">Links</a>
<a href="/about">About</a>
<a href="/resources">Resources</a>

So I started using History.js to link up each slide with it's respective link; www.example.com/about. I can change the state with no issue; back and forward work and the URL changes.

What I did happen to notice is that if I load the page with a false URL like, www.example.com/about, the page returns a 404.

What can I do to prevent the 404 from occurring, but also making sure the page is taken to the correct slide?

Is there another way I should be doing this?

I'm in a LAMP stack with jQuery and HTML5.

I'm really stuck on this one...thanks!

4

2 回答 2

1

如果我对您的理解正确,您实际上必须创建/about/gallery等页面。想一想——History API 只能在一个页面中工作。它操纵地址栏的内容,但它不会自行创建实际的 URL。

我的解决方案是使用类似 mod_rewrite 的东西。/about会重定向到类似的东西/?p=about,它会加载您的页面,并且相应的div已经打开。其他幻灯片也一样。只有这样您才能使用 History API 的功能。

于 2012-01-24T09:27:20.320 回答
0

它是我们处理 HTTP 404 错误的 Web 服务器,请参阅您的 Web 服务器文档以了解如何使用重定向等创建自定义错误页面。如果您使用的是 Microsoft Internet Information Server 7,请查看此处http://blogs.iis.net/rakkimk /archive/2008/10/03/iis7-enabling-custom-error-pages.aspx

于 2011-07-13T00:07:32.577 回答