【问题标题】:PHP how to open page1, redirect to page2 and show page1 in a div dom?PHP如何打开page1,重定向到page2并在div dom中显示page1?
【发布时间】:2011-09-09 22:40:03
【问题描述】:

我有很多子页面,有www.domain.com/sub/page1.phpwww.domain.com/sub/page2.php 之类的网址...现在当我在浏览器中输入网址时。它们都重定向到www.domain.com/sub/index.php,并且当前子页面将显示在index.php 的一个div dom 中。

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

补充一点:也应该想到SEO。也许jqeury.load 对搜索蜘蛛不利。也许应该使用hash url。

所以我寻求帮助。有没有人可以给我一些好的建议?还是简单的例子?

谢谢。

【问题讨论】:

  • 重定向是怎么做的?通过javascript?还是 Apache ModRewrite?
  • @ArtoAle,我绑定了header Location,但不是success.so javascript?或 Apache ModRewrite。一切都很好,只是得到效果。谢谢。
  • 如果您在另一个页面中加载一个页面,iFrame 会不会更好?

标签: php javascript jquery redirect


【解决方案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>

【讨论】:

  • 好方法。还有一个问题:如果page1.php在文件夹名称files中。(文件是Web根目录中的子文件夹)如何写header('Location:?非常感谢。
  • 应该是header('Location: ../index.php。您还可以将header('Location: /sub/index.php 用于子文件夹(称为files)和Web 根目录中的文件。
猜你喜欢
  • 1970-01-01
  • 2023-03-30
  • 2012-03-12
  • 2020-10-10
  • 2020-10-09
  • 1970-01-01
  • 1970-01-01
  • 2020-10-17
  • 1970-01-01
相关资源
最近更新 更多