我在http://site.com/services/有一个页面,我只想将其重定向到http://site.com/servics/first-service/
最佳重定向是什么,我该怎么做?
答案 0 :(得分:7)
<强> PHP 强>:
header("Location: yourpage.php");
exit;
您必须在exit
之后使用die
或header
才能停止执行您的代码。
此外,代码必须在任何输出之前执行。
<强> 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)
答案 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/";
?我希望它有效。