PHP如何打开page1,重定向到page2并在div dom中显示page1?

时间:2011-06-07 09:47:09

标签: php javascript jquery redirect

我有很多子页面,有www.domain.com/sub/page1.php www.domain.com/sub/page2.php等网址...现在我在浏览器中输入了url。它们全部重定向到www.domain.com/sub/index.php,当前子页面将显示在index.php的div dom中。

我的知识非常有限。我只知道jqeury.loadphp header Location。但很难重定向到index.php,然后告诉index.php,这是当前的子页面然后执行jqeury.load

再补充一点:还应该考虑SEO。也许jqeury.load对搜索蜘蛛不利。也许应该使用hash网址。

所以我请求帮助。有人能给我一些好的建议吗?或简单的工作实例?

感谢。

1 个答案:

答案 0 :(得分:1)

在每个PHP文件中(例如page1.php)使用以下代码:

<?php
if(!defined('INCLUDE')) {
    header('Location: index.php?site=' . $_SERVER['PHP_SELF']); //Send the user to the index.php page
    die();
}
?>
Insert the content you want here...

index.php文件中:

<?php
define('INCLUDE', true);
if(isset($_GET['site'])) {
    $site = $_GET['site'];
} else {
    $site = 'page100.php'; //Put the name of the default page if the user visits index.php here
}
?>
<html>
<head><!-- HEAD CONTENT HERE --></head>
<body>
<div><?php 
include($site); //Put the page requested into the div
?></div>
</body>
</html>