Home > Backend Development > PHP Tutorial > 301 web page redirect code list

301 web page redirect code list

WBOY
Release: 2016-07-25 08:53:01
Original
3364 people have browsed it
  1. Header( "HTTP/1.1 301 Moved Permanently" );
  2. Header( "Location: http://www.new-url.com" );
  3. ?>
复制代码

3. ASP Redirect

  1. <%@ Language=VBScript %>
  2. <%
  3. Response.Status="301 Moved Permanently"
  4. Response.AddHeader "Location","http://www.new-url.com/"
  5. %>
复制代码

4. ASP .NET Redirect

复制代码

5. JSP Redirect

  1. <%
  2. response.setStatus(301);
  3. response.setHeader( "Location", "http://www.new-url.com/" );
  4. response.setHeader( "Connection", "close" );
  5. %>
复制代码

6. CGI PERL Redirect

  1. $q = new CGI;
  2. print $q->redirect("http://www.new-url.com/");
复制代码

7. Ruby on Rails Redirect

  1. def old_action
  2. headers["Status"] = "301 Moved Permanently"
  3. redirect_to "http://www.new-url.com/"
  4. end
复制代码

8. ColdFusion Redirect

  1. <.cfheader statuscode="301" statustext="Moved permanently">
  2. <.cfheader name="Location" value="http://www.new-url.com">
复制代码

9. Javascript URL Redirect

复制代码

10. IIS Redirect 在 Internet 服务管理器中右击你想要重定向的文件和文件夹,选择 "a redirection to a URL". (bbs.it-home.org 编辑整理) 然后输入目标网址,选中 "The exact url entered above" 和 "A permanent redirection for this resource" 然后点击 'Apply' 按钮。

11. 使用 .htaccess 进行重定向 创建一个 .htaccess 文件用来将访问 domain.com 重定向到 www.domain.com 下,该文件必须放置在网站的root目录,也就是首页放置的目录。

  1. Options +FollowSymlinks
  2. RewriteEngine on
  3. rewritecond %{http_host} ^domain.com [nc]
  4. rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
复制代码

注意: .htaccess 方法的重定向只能在 Linux 下使用 Apache 的 mod_rewrite 模块启用的情况下使用。

推荐阅读:
  • .htaccess实现301域名重定向
  • apache rewrite重定向的例子
  • htaccess 重定向所有请求到某个URL地址
  • htaccess防盗链、301重定向、限制网站访问
  • apache 301重定向配置实例
  • apache 301重定向

12.Nginx中的rewrite

  1. server {
  2. server_name bbs.it-home.org jbxue.com;
  3. if ($host = 'jbxue.com' ) {
  4. rewrite ^/(.*)$ http://bbs.it-home.org/$1 permanent;
  5. }
复制代码


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template