Simple Page Redirect?

半城伤御伤魂 提交于 2019-12-30 11:47:06

问题


I have a page at http://site.com/services/ and I just want to redirect it to http://site.com/servics/first-service/

Whats the best redirect to do this and how do I do this?


回答1:


PHP:

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

You have to use exit or die after header in order to stop execution of your code. Also, the code has to be executed before any output.


HTML:

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

The code should be placed between <head></head> tags.


JavaScript:

window.location = "yourpage.php";

.htaccess:

Redirect 301 /oldpage.php /newpage.php



回答2:


This can be accomplished with a simple Redirect directive.

Redirect /services /services/first-service

You can choose what kind of a response code you will send to the client. Further info on that on the link I provided.




回答3:


If it is a permanent change, you want to use a 301 redirect google has some good content on the matter

To build the redirect just add

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

to .htacess on the top level of your directory tree. NOTE I switched 'servcs' from your example to services




回答4:


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




回答5:


I use this as an Index file in the folder's that I don't want the public to brows,,,,

    <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//

?>



回答6:


Have you tried javascript window.location = "http://site.com/servics/first-service/"; ? I hope it works.



来源:https://stackoverflow.com/questions/11441146/simple-page-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!