0

I have designed a webpage using few html files. I have an index.html file as homepage. I need to start displaying my webpage from index.html. It's working fine when opened the respective link. But when i browse the secondpage link in search bar, it navigates directly to secondpage skkiping the index page. how can i protect this behaviour?

4

2 回答 2

1

让您的服务器在访问索引页面时设置一个 cookie。

测试所有其他页面上是否存在该 cookie,如果不存在则重定向。

(或者不要打扰,深度链接是 WWW 的自然组成部分)。

于 2013-08-02T14:51:44.637 回答
0

正如您所说,您想要一个 javascript 解决方案而不是带有 mod_rewrite 的解决方案:将以下(未经测试的)脚本添加到每个页面:

//Check if the cookie is set
if( document.cookie.indexOf( 'myuniqueindexcookie' ) == -1 ) {
  //It isn't, so redirect to the index page
  document.location = "http://my.site/my/index.php";
}

在 index.php 上放置以下 javascript 行

document.cookie = "myuniqueindexcookie=1; expires=0; path=/";

显然,当用户关闭 javascript 时,这将不起作用。

于 2013-08-05T11:13:34.330 回答