實現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狀態碼