windows中apache 301頁面跳轉實現方法_Linux

來源:互聯網
上載者:User
實現301頁面跳轉之前需要對apache配置做下修改如

apache預設是沒有開啟mod_rewrite模組的,

1,將

複製代碼 代碼如下:
#LoadModule rewrite_module modules/mod_rewrite.so

這一行前面的#號去掉,http.conf的網站目錄配置,另一種是空間使用者常用的

改為

複製代碼 代碼如下:
LoadModule rewrite_module modules/mod_rewrite.so,


2,將AllowOverride None 改為:AllowOverride All

一、寫.htaccess檔案,關於301重新導向的寫法:

1) 常見的將不帶WWW的網域名稱轉向到帶WWW的網域名稱下 舉例:網站.com重新導向到www.網站.com

複製代碼 代碼如下:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^網站.com [NC]
RewriteRule ^(.*)$ http://www.網站.com/$1 [L,R=301]


如果你有伺服器許可權我們可以在http.conf中修改

二、Apache下vhosts.conf中配置301轉向。

複製代碼 代碼如下:

<VirtualHost *:80>
DocumentRoot “E:/xxx”
ServerName http://www.網域名稱.net
</VirtualHost>
<VirtualHost *:80>
ServerName 網域名稱.net
RedirectMatch permanent ^/(.*) http://www.網域名稱.net$1
</VirtualHost>



將不帶WWW的網域名稱轉向到帶WWW的網域名稱下

複製代碼 代碼如下:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xxx.cn [NC]
RewriteRule ^(.*)$ http://www.xxx,cn/$1 [L,R=301]

常用的用戶端請求錯誤傳回碼:

400 - Bad request 錯誤請求
401 Authorization Required需要驗證
403 Forbidden禁止
404 Not Found找不到頁面
405 Method Not Allowed
408 Request Timed Out
411 Content Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type

大家可使用ff瀏覽firebug來檢測是否返回了301狀態碼
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.