我有很多子页面,有www.domain.com/sub/page1.php
www.domain.com/sub/page2.php
等网址...现在我在浏览器中输入了url。它们全部重定向到www.domain.com/sub/index.php
,当前子页面将显示在index.php
的div dom中。
我的知识非常有限。我只知道jqeury.load
和php header Location
。但很难重定向到index.php
,然后告诉index.php
,这是当前的子页面然后执行jqeury.load
。
再补充一点:还应该考虑SEO
。也许jqeury.load
对搜索蜘蛛不利。也许应该使用hash
网址。
所以我请求帮助。有人能给我一些好的建议吗?或简单的工作实例?
感谢。
答案 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>