zoukankan      html  css  js  c++  java
  • 重定向

    第一种:利用header()函数进行重定向,这也是我用的较多的。(注意!locationhe和“:”之间不能有空格,否则无作用!)

    <?php
    header('content-type:text/html;charset=uft-8);
    //重定向页面
    header('location:index.php');
    ?>
    第二种:利用HTML 头部中的 meta标签,定义http-equiv=refresh 和content=”跳转花费的时间(秒为单位);url=跳转地址”

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    //跳转页面,跳转时间:3秒钟,目标地址:index.php
    <meta http-equiv="refresh" content="3;url=index.php">
    <title>skip...</title>
    </head>

    或者

    <?php
    header('content-type:text/html;charset=utf-8');
    $url='index.php';
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    //跳转页面,跳转时间:2秒钟,目标地址:index.php
    <meta http-equiv="refresh" content="2;url=<?php echo $url; ?>">
    <title>skip...</title>
    </head>

    第三种:利用javascript进行跳转

    <?php
    header('content-type:text/html;charset=utf-8');
    $url='index.php';
    //立即跳转至目标页面
    echo <script>window.location.href='$url';</script>;
    ?>

    以上就是PHP中重定向页面的三种方法。

        

    1,将www.myweb.com/connect 跳转到connect.myweb.com

    rewrite ^/connect$ http://connect.myweb.com permanent;

    rewrite ^/connect/(.*)$ http://connect.myweb.com/$1 permanent;

    2,将connect.myweb.com 301跳转到www.myweb.com/connect/ 

    if ($host = "connect.myweb.com"){

    rewrite ^/(.*)$ http://www.myweb.com/connect/$1 permanent;

        }

    3,myweb.com 跳转到www.myweb.com

    if ($host != 'www.myweb.com' ) { 

    rewrite ^/(.*)$ http://www.myweb.com/$1 permanent; 

        }

    4,www.myweb.com/category/123.html 跳转为 category/?cd=123

    rewrite "/category/(.*).html$" /category/?cd=$1 last;

    5,www.myweb.com/admin/ 下跳转为www.myweb.com/admin/index.php?s=

    if (!-e $request_filename){

    rewrite ^/admin/(.*)$ /admin/index.php?s=/$1 last;

        }

  • 相关阅读:
    SQL函数union,union all整理
    Oracle中的having()函数
    SQL函数count(),sum()理解
    Office Online Server 和 SharePoint 2016配置时报错
    Manjaro 黑苹果网卡BCM4360折腾记
    Manjaro安装与基本配置
    在Arch Linux/Manjaro上安装KVM、QEMU和Virt Manager的方法
    Nginx 优化详解
    xargs 使用详解
    Centos7 搭建lnmp环境 (centos7+nginx+MySQL5.7.9+PHP7)
  • 原文地址:https://www.cnblogs.com/liliuguang/p/10621018.html
Copyright © 2011-2022 走看看