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
.
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
.
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?
Thanks.
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...
And in the index.php
file:
<?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>