301網頁重新導向代碼大全

來源:互聯網
上載者:User
  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在 網際網路服務管理員中右擊你想要重新導向的檔案和檔案夾,選擇 "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. }
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.