简单的页面重定向?

时间:2012-07-11 20:41:41

标签: php .htaccess redirect

我在http://site.com/services/有一个页面,我只想将其重定向到http://site.com/servics/first-service/

最佳重定向是什么,我该怎么做?

6 个答案:

答案 0 :(得分:7)

<强> PHP

header("Location: yourpage.php");
exit;

您必须在exit之后使用dieheader才能停止执行您的代码。 此外,代码必须在任何输出之前执行。


<强> HTML

<meta http-equiv="refresh" content="0;url=yourpage.php">

代码应放在<head></head>代码之间。


<强>的JavaScript

window.location = "yourpage.php";

<强>的.htaccess

Redirect 301 /oldpage.php /newpage.php

答案 1 :(得分:1)

这可以通过简单的Redirect指令来完成。

Redirect /services /services/first-service

您可以选择要发送给客户的响应代码类型。关于我提供的链接的更多信息。

答案 2 :(得分:1)

如果是永久性更改,您想使用301重定向google有一些good content on the matter

要构建重定向,只需添加

redirect 301 /services/  http://site.com/services/first-service/

到目录树顶层的.htacess。 注意我将“servcs”从您的示例切换为服务

答案 3 :(得分:0)

在javascript中:window.location = "/first-service";

答案 4 :(得分:0)

我将其用作文件夹中的索引文件,我不希望公众看到,...,

    <meta name="robots" content="noindex, nofollow" />
    <meta name="googlebot" content="noindex, nofollow" />

<?php

$url = 'http://' . $_SERVER['HTTP_HOST'];            // Get the server//

header('Location: ' . $url, true, 301);              // Use either 301 or 302//

?>

答案 5 :(得分:-1)

您是否尝试过javascript window.location = "http://site.com/servics/first-service/";?我希望它有效。

相关问题