PHP如何在div dom中打开page1,重定向到page2并显示page1?
我有很多子页面,其中的URL如www.domain.com/sub/page1.php
www.domain.com/sub/page2.php
...现在,当我在浏览器中键入URL时.它们都重定向到www.domain.com/sub/index.php
,并且当前子页面将显示在index.php
中的一个div中.
I have many sub pages, there urls like www.domain.com/sub/page1.php
www.domain.com/sub/page2.php
... Now when I type there url in browser. they all redirect to www.domain.com/sub/index.php
, and the current sub page will show in a div dom in the index.php
.
我的知识非常有限.我只知道jqeury.load
和php header Location
.但是很难重定向到index.php
然后告诉index.php
,这是当前的子页面,然后执行jqeury.load
.
My knowledge is very limited. I only know jqeury.load
and php header Location
. but it is difficult redirect to index.php
then tell index.php
, which is the current sub-pages then do a jqeury.load
.
需要注意的另一点:也应该考虑SEO
. jqeury.load
可能对搜索蜘蛛不利.也许应该使用hash
网址.
One more note: Also should think SEO
. maybe jqeury.load
is bad for a search spider. maybe should use hash
url.
所以我寻求帮助.有没有人可以给我一些好的建议?或简单的示例?
So I ask for a help. is there anybody could give me some good suggestion? or simple worked examples?
谢谢.
在每个PHP文件(例如page1.php
)中,使用以下代码:
In every PHP file (e.g page1.php
) use this code:
<?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>