您的位置:HBcms宏博内容管理系统 建站经验 正文
 添加时间:2008-03-05 原文发表:2008-03-05 人气:140


使用Redirect或urlRewrite在.htaccess文件里设置301跳转, .htaccess,這個檔案通常會在網站的根目錄,如果沒有,就自己用 Notepad 新增一個。你的作業系統不允許 .htaccess 這樣的檔案名稱時,就先把它命名為 htaccess.txt,上傳到 FTP 之後,再把檔案名稱改成 .htaccess。

 

--------------- 網頁伺服器必須是 Apache ---------------

 

【情況一】

 

http://your_domain.com/wordpress >> http://your_domain.com/blog

 

讓連接到 /wordpress 的連結重新定址到 /blog,包含下層路徑

例如:http://vinta.ws/wordpress/?p=334 會被指向 http://vinta.ws/blog/?p=334

 

在 .htaccess 中要這麼寫:

 

Redirect /wordpress http://your_domain.com/blog

 

如果有安裝 mod_rewrite 模組的話,也可以這樣寫:

 

RewriteEngine on

RewriteRule ^wordpress(.*)$ /blog$1 [R=301,L]

 

 

【情況二】

 

http://your_domain.com/wordpress >> http://your_domain.com

 

讓連接到 /wordpress 的連結重新定址到 根目錄,包含下層路徑(如 /wordpress/xxx)

 

在 .htaccess 中要這麼寫:

 

Redirect /wordpress http://your_domain.com

 

如果有安裝 mod_rewrite 模組的話,也可以這樣寫:

 

RewriteEngine on

RewriteRule ^wordpress(.*)$ $1 [R=301,L]

 

【情況三】

 

http://old_domain.com/ >> http://new_domain.com/

 

讓連接到 舊網址 的連結重新定址到 新網址,前提是你必須是舊網址的擁有者

建議讓 舊網址 和 新網址 包持相同的目錄結構

 

把 .htaccess 放到 舊網址 的根目錄,然後要這麼寫:

 

RewriteEngine on

RewriteRule (.*) http://new_domain.com/$1 [R=301,L]

 

【情況四】

 

http://www.your_domain.com/ >> http://your_domain.com/

 

統一你的網址,不要出現 www

由 www.your_domain.com 進入的連結一律重新指向 your_domain.com

 

可以在 .htaccess 中這麼寫:

 

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.your_domain\.com$ [NC]

RewriteRule ^(.*)$ http://your_domain.com/$1 [R=301,L]

 

------------ BLOG 不應該放在根目錄啊~ ------------

 

【技巧一】

 

確保你的網站實行了 301 Redirect,可以到 Search Engine Friendly Redirect Checker 檢查。輸入要檢查的網址和驗證碼就可以了。

 

【技巧二】

 

防止 .htaccess 檔案被檢視,則要在 .htaccess 中加入:

 

<files .htaccess>

order allow,deny

deny from all

</files>

 

【技巧三】

 

通常該目錄中沒有 index.html 的時候,Apache 會把此目錄下的檔案統統列出來。如果你不想這麼做的話,在 .htaccess 中加入這一行:

 

Options -Indexes

来源: http://vinta.ws/blog/370

本页地址
相关文章

有关贵站经营的建议
如何安装apache2的deflate压缩?mod_deflat
我的做网站及赚钱之路
网站运营经历
【原创】一段建免费论坛的经历!!
如何申请百度解封?百度重新收录网站的方法
网页设计中颜色搭配的重要性,常见颜色的含义
网页设计中颜色的搭配
站长常用代码
记录访客的来访次数,并根据作出不同的提示
DHTML中文参考教程,中文DHTML手册
如何防止页面被人直接复制拷贝?

相关评论


本文章所属分类:首页 建站经验