Javascript 同时使用index.html和index.php时,从URL隐藏index.php
我有一个同时使用index.html和index.php的网站。index.html是一个年龄限制启动页面,当单击某个按钮上的“是”时,您将使用index.php重新定向到主站点,这是一个没有任何/子域的单页滚动程序 我想做的是,当您被重定向到index.php时,隐藏example.com/index.php URL的index.php。。。我已经搜索了整个网络,但还没有找到一个有效的解决方案 修改.htaccess不起作用,我认为那里的任何代码都做不到我想要的(我自己也没有写过)。我曾尝试将iFrame与JavaScript结合使用,但很难找到有效的解决方案。我的结论是对index.php使用DirectoryIndex,但当然index.html不起作用 我相信有一个简单的解决办法,但我的想法是错误的。我该如何着手解决这个问题Javascript 同时使用index.html和index.php时,从URL隐藏index.php,javascript,php,jquery,html,.htaccess,Javascript,Php,Jquery,Html,.htaccess,我有一个同时使用index.html和index.php的网站。index.html是一个年龄限制启动页面,当单击某个按钮上的“是”时,您将使用index.php重新定向到主站点,这是一个没有任何/子域的单页滚动程序 我想做的是,当您被重定向到index.php时,隐藏example.com/index.php URL的index.php。。。我已经搜索了整个网络,但还没有找到一个有效的解决方案 修改.htaccess不起作用,我认为那里的任何代码都做不到我想要的(我自己也没有写过)。我曾尝试将
谢谢你抽出时间 一种方法是将以下内容添加到
.htaccess
文件中:
DirectoryIndex index.php index.html
这将使用index.php
作为默认索引文件。在php文件中,您可以这样做,以便在用户第一次访问您的站点时显示index.html
:
// start a new session and check if the index.html have been included
session_start();
if(!isset($_SESSION['index_included'])) {
// display the index.html and exit script
// notice that we are setting index_included to true in our session
include_once('index.html');
$_SESSION['index_included'] = 1;
exit;
}
// rest of your php goes here
如果要标记用户已单击index.html
中的按钮,可以使用ajax:
<!DOCTYPE html>
<html>
<head>
<title>Sample Index.html</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
// index.html
$(document).ready(function() {
//
$('#button').click(function() {
// make an ajax request to index.php to tell that the button
// is clicked
$.ajax('index.php', {
type : 'post',
data : 'clicked=true',
success:function() {
// reload the location to send user to index.php
window.location.reload();
}
});
return false;
});
});
</script>
<body>
<a href="#" id="button">click me</a>
</body>
</html>
或者,您可以使用setcookie()
,而不是将状态存储在会话中。像这样的方法应该会奏效:
// index.php
if(isset($_POST['clicked'])) {
setcookie('clicked', true);
exit;
}
if(!isset($_COOKIE['clicked'])) {
include_once('index.html');
exit;
}
// rest of index.php
您可以查看
php.ini
文件并添加expose\u php=off
语句。
虽然我从未试过,但我认为这正是你想要的
这可能还有一些额外的提示,告诉您如何将正在使用的扩展屏蔽为它们所没有的扩展
----更新---
在阅读了Cyclone给出的答案后,由于它代表了一个与我认为你的问题完全不同的问题的解决方案,我再次阅读了你的问题,觉得我给了你错误的答案。不过,我会让它留在上面,以防我第二次误读
因此,如果您试图从链接http://example.com/index.php
没有真正的方法可以让它完全消失,因为用户可能会键入它,或者通过编写它的链接到达那里。但是,您可以重定向到http://example.com/
而不是http://example.com/index.php
如果您同时拥有
index.html
和index.php
,那么只有当您使用Cyclone的应答从index.php
中调用index.html
,并使其不再出现时,这才有效。您必须提供一些代码,以便我们提供帮助。应该检查他们是否单击了“我是“此内容的适当年龄”按钮。不仅仅是他们访问了index.html页面。@greg_diesel-我理解,我只是指出他可以通过php在会话中设置一些东西来实现这一点。在这种特殊情况下,如何做到这一点取决于他。例如,当用户在index.html中执行某些操作并设置一些变量时,您可以向index.php发出一个ajax请求。@greg_diesel-关键是它是一个处理所有请求的文件。如果你不明白,我可以更新我的帖子并给出真实的例子?
// index.php
if(isset($_POST['clicked'])) {
setcookie('clicked', true);
exit;
}
if(!isset($_COOKIE['clicked'])) {
include_once('index.html');
exit;
}
// rest of index.php