Apache中301重定向的配置代碼
更新時間:2011年02月24日 00:06:04 作者:
Apache下301重定向代碼(因為我使用的是WINDOWS 2003 + APACHE 所以本文僅限APACHE服務器使用。)
新建.htaccess文件,輸入下列內容(需要開啟mod_rewrite):
1)將不帶WWW的域名轉向到帶WWW的域名下
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^jb51.net [NC]
RewriteRule ^(.*)$ http://www.dbjr.com.cn/$1 [L,R=301]
2)重定向到新域名
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.baidu.com/$1 [L,R=301]
3)使用正則進行301重定向,實現偽靜態(tài)
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?id=$1
將news.php?id=123這樣的地址轉向到news-123.html
Apache下vhosts.conf中配置301重定向
為實現URL規(guī)范化,SEO通常將不帶WWW的域名轉向到帶WWW域名,vhosts.conf中配置為:
<VirtualHost *:80>
ServerName www.baidu.com
DocumentRoot /home/fari001Com
</VirtualHost>
<VirtualHost *:80>
ServerName faribaidu.com
RedirectMatch permanent ^/(.*) http://www.baidu.com/$1
</VirtualHost>
Apache下除了以上2種方法,還有其他配置方法和可選參數,建議閱讀Apache文檔。
1)將不帶WWW的域名轉向到帶WWW的域名下
復制代碼 代碼如下:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^jb51.net [NC]
RewriteRule ^(.*)$ http://www.dbjr.com.cn/$1 [L,R=301]
2)重定向到新域名
復制代碼 代碼如下:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.baidu.com/$1 [L,R=301]
3)使用正則進行301重定向,實現偽靜態(tài)
復制代碼 代碼如下:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?id=$1
將news.php?id=123這樣的地址轉向到news-123.html
Apache下vhosts.conf中配置301重定向
為實現URL規(guī)范化,SEO通常將不帶WWW的域名轉向到帶WWW域名,vhosts.conf中配置為:
復制代碼 代碼如下:
<VirtualHost *:80>
ServerName www.baidu.com
DocumentRoot /home/fari001Com
</VirtualHost>
<VirtualHost *:80>
ServerName faribaidu.com
RedirectMatch permanent ^/(.*) http://www.baidu.com/$1
</VirtualHost>
Apache下除了以上2種方法,還有其他配置方法和可選參數,建議閱讀Apache文檔。
相關文章
Linux下安裝grafana并且添加influxdb監(jiān)控的方法
這篇文章主要介紹了Linux下安裝grafana并且添加influxdb監(jiān)控的方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12
centos7.2.1511安裝jdk1.8.0_151及mysql5.6.38的方法
這篇文章主要介紹了centos7.2.1511安裝jdk1.8.0_151及mysql5.6.38的方法,較為詳細的講述了centos7.2.1511安裝jdk1.8.0_151及mysql5.6.38的具體步驟與相關設置技巧,需要的朋友可以參考下2018-01-01
linux如何為已存在的用戶創(chuàng)建home目錄
這篇文章主要介紹了linux如何為已存在的用戶創(chuàng)建home目錄問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04

