nodejs 重定向 (redirect + writeHead(Location))
参考:
Express URL跳转(重定向)的实现:res.location()与res.redirect()
一 方式1
index.js
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(301, {'Location': 'http://itbilu.com/'});
console.log(res._header);
res.end();
});
server.listen(3000);
浏览器打开http://127.0.0.1:3000,页面跳转到http://itbilu.com。
一 方式2
index.js
var http = require('http');
var server = http.createServer(function (req, res) {
res.redirect('http://itbilu.com/');
//res.redirect(301,'http://itbilu.com/');
res.end(); }); server.listen(3000);
res.redirect更简便,二者区别?
nodejs 重定向 (redirect + writeHead(Location))的更多相关文章
- response.redirect 与location.href 的区别
最近做项目时发现,先弹出提示框,再跳转页面 这样写:Jscript.Alert("你好,Hello!"); Response.Redirect("/index.aspx& ...
- .htaccess技巧: URL重写(Rewrite)与重定向(Redirect)
URL重定向是.htaccess的重头戏,它可以将长地址转为短地址.将动态地址转为静态地址.重定向丢失的页面.防止盗链.实现自动语言转换等.笔者觉得难点是在正则表达式的运用和理解上. 实现所有这些神奇 ...
- .htaccess技巧: URL重写(Rewrite)与重定向(Redirect) (转)
目录 Table of Contents 一.准备开始:mod_rewrite 二.利用.htaccess实现URL重写(rewrite)与URL重定向(redirect) 将.htm页面映射到.ph ...
- thinkphp 重定向redirect
/** * URL重定向 * @param string $url 重定向的URL地址 * @param integer $time 重定向的等待时间(秒) * @param string $msg ...
- 转发(Forward)和重定向(Redirect)的区别
转发是服务器行为,重定向是客户端行为. 转发(Forword) :通过RequestDispatcher对象的forward(HttpServletRequest request,HttpServle ...
- Response.Redirect & window.location.href
对接中信的微信H5支付时,对方(其实是微信)需要对我们的域名进行授权,即,我方需向渠道报备支付域名,微信只认可由此域名发起的支付交易. 支付中心只提供了一套支付接口供下游系统访问.因为给渠道报备的域名 ...
- CI框架 重定向redirect()
CI框架不能使用$this->redirect(),只能使用redirect():并且默认重定向地址带有index.php,如果需要去掉,请使用绝对地址. 使用示例: 通过发送HTTP头,命令客 ...
- 重定向redirect与跳转forward区别
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DemoResponse.a ...
- Header() in PHP &html – Refresh (Redirect) to Location (URL) in X seconds
Case 1 : Redirect a page to a URL without waiting in PHP. 1 header("Location: index.php"); ...
随机推荐
- Hibernate- 连接查询
01.搭建开发环境 02.连接查询 package com.gordon.test; import java.util.Arrays; import java.util.List; import or ...
- Aria2 懒人安装教程
https://aria2.github.io/ uI版:https://github.com/ziahamza/webui-aria2 web的 可以在线使用的 https://ziahamza.g ...
- 说说$POST 、$HTTP_RAW_POST_DATA、php://input三者之间的区别
$POST $_POST是我们最常用的获取POST数据的方式,它是以关联数组方式组织提交的数据,并对此进行编码处理,如urldecode,甚至编码转换,识别的数据类型是PHP默认识别的数据类型 app ...
- JQuery _ 定时器(jQuery Timers) 学习
jQuery Timers插件地址: http://plugins.jquery.com/project/timers JQuery Timers应用知识 提供了三个函式 1. everyTime(时 ...
- 关于Java获取文件路径的几种方法
第一种:File f = new File(this.getClass().getResource("/").getPath()); System.out.println(f); ...
- python扩展
补充一些有趣的知识 1. sys模块方法的补充,打印进度条 import sys,time for i in range(20): sys.stdout.write("#") sy ...
- C++ 判断目录是否存在并新建目录
http://blog.csdn.net/u012005313/article/details/50688257 #include <io.h> #include <string&g ...
- C# VS本地Sqlserver 操作笔记
1.如何连接本地数据库 -- string Info = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirecto ...
- Java的四种引用类型之弱引用
先说结论: 首先,Java中有四种引用类型:强引用.软引用.弱引用.虚引用.-- 在 Java 1.2 中添加的,见 package java.lang.ref; . 其次,这几个概念是与垃圾回收有关 ...
- e662. 取的图像的色彩模型
// This method returns the color model of an image public static ColorModel getColorModel(Image imag ...