<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.htaccess | SEO研究院</title>
	<atom:link href="https://seo.dns.com.tw/archives/tag/htaccess/feed" rel="self" type="application/rss+xml" />
	<link>https://seo.dns.com.tw</link>
	<description></description>
	<lastBuildDate>Fri, 10 Aug 2012 05:18:43 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://seo.dns.com.tw/wp-content/uploads/2022/11/seo.jpg</url>
	<title>.htaccess | SEO研究院</title>
	<link>https://seo.dns.com.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>robots.txt與.htaccess檔案的用途是什麼?</title>
		<link>https://seo.dns.com.tw/archives/6619</link>
					<comments>https://seo.dns.com.tw/archives/6619#respond</comments>
		
		<dc:creator><![CDATA[SEO]]></dc:creator>
		<pubDate>Fri, 10 Aug 2012 05:18:43 +0000</pubDate>
				<category><![CDATA[SEO搜尋引擎優化]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[robots.txt]]></category>
		<category><![CDATA[Website]]></category>
		<category><![CDATA[網站優化]]></category>
		<guid isPermaLink="false">http://www.dns.com.tw/seo/?p=6619</guid>

					<description><![CDATA[<p>經常有人會誤會robots.txt與.htaccess檔案的 ...</p>
The post <a href="https://seo.dns.com.tw/archives/6619">robots.txt與.htaccess檔案的用途是什麼?</a> first appeared on <a href="https://seo.dns.com.tw">SEO研究院</a>.]]></description>
										<content:encoded><![CDATA[<p>經常有人會誤會robots.txt與.htaccess檔案的用法，所以我們特別整理資料來說明 &#8230;</p>
<p><span id="more-6619"></span></p>
<p>robots.txt與.htaccess檔案最簡單並且應該知道的事項如下:</p>
<p>(1)robots.txt放置在www根目錄下，.htaccess檔案最好是放置在非www根目錄下(依照Apache安裝設定)。</p>
<p>例如某個空間 /home/yourhosting/ 是你的根目錄</p>
<p>可以設定 /home/yourhosting/www/ 當成是你的www根目錄</p>
<p>(2)robots.txt的目的是告訴搜尋引擎的爬蟲程式，哪些可以抓取，哪些不要抓取。</p>
<p>(3)robots.txt的作用只是告知性質，如果搜尋引擎的爬蟲程式不理會，也沒有辦法。</p>
<p>(4).htaccess檔案是搭配Apache web伺服器軟體運作，其他類型的伺服器軟體未必也使用相同方式。例如如果是Windows IIS 7的話，則是使用web.config來保存應用程式整合設定 (<a href="http://www.microsoft.com/taiwan/technet/iis/learn/translate-htaccess-content-to-iis-webconfig.aspx" target="_blank">參考</a>)。</p>
<p>(5).htaccess檔案的目的是處理進到網站的所有連線的權限與方式。</p>
<p>(6).htaccess檔案的作用不是告知性質，連線進來就會依照.htaccess檔案內的語法處理。</p>
<p>(7)robots.txt與.htaccess檔案各有其不同的語法。</p>
<p>例如你可以看看Yahoo的robots.txt樣子~ <a href="http://www.yahoo.com/robots.txt">http://www.yahoo.com/robots.txt</a></p>
<p>所以有沒有注意到? 任何人都可以看到網站的robots.txt檔案，所以你如果有內部使用的目錄，而沒有密碼保護的話，千萬不要把他列在robots.txt內，因為等於告訴大家這裡有機密檔案。就算有密碼保護，其實也是一種安全疑慮，最好不要把內部文件放置在對外公開的伺服器上。</p>
<p>那麼robots.txt應該如何設定呢? 你也可以參考 wikipedia關於<a href="http://zh.wikipedia.org/wiki/Robots.txt" target="_blank">robots.txt的解釋</a></p>
<p>(1)如果你沒有特別需要限制，大都robots.txt內容如下~</p>
<p><span style="color: red;">User-agent: *<br />
Disallow:</span></p>
<p>如果你不允許任何爬蟲程式連線，內容如下</p>
<p><span style="color: red;">User-agent: *<br />
Disallow: /</span></p>
<p>如果你不允許任何爬蟲程式抓取特定目錄，內容如下</p>
<p><span style="color: red;">User-agent: *<br />
Disallow: /cgi-bin/<br />
Disallow: /images/<br />
Disallow: /tmp/<br />
Disallow: /private/</span></p>
<p>當然前面有說到，只是告知性質，爬蟲程式如果不遵守，你也沒皮條就是了。</p>
<p>(2)上面說到的User-agent，就是指定哪些特定的爬蟲程式，星號(*)就是表示所有的爬蟲程式。</p>
<p>例如: Google的User-agent是 <a href="http://www.google.com/support/webmasters/bin/answer.py?answer=182072" target="_blank">googlebot</a>，Bing的User-agent是 <a href="http://www.bing.com/community/site_blogs/b/webmaster/archive/2010/09/03/bingbot-is-coming-to-town.aspx" target="_blank">bingbot</a></p>
<p>(微軟的msnbot已經於2010/10/1後不再使用)</p>
<p>而百度的User-agent則是baiduspider，但是百度還是其他的user-agent，請參考 <a href="http://www.baidu.com/search/spider.htm">http://www.baidu.com/search/spider.htm</a></p>
<p>(3)那麼robots.txt還有其他的寫法嗎? 你可以利用具來產生robots.txt。</p>
<p><a href="http://www.searchenginepromotionhelp.com/m/robots-text-creator/simple-robots-creator.php" target="_blank">http://www.searchenginepromotionhelp.com/m/robots-text-creator/simple-robots-creator.php</a></p>
<p>利用這個工具產生之後，再上傳到網站www的根目錄，再使用Google Webmasters去測試是否正確即可。</p>
<p>robots.txt的觀念非常簡單的，不是嗎? 線上還有許多robots.txt generator，你可以自己找看看。</p>
<p>但是關於.htaccess，就不是這麼簡單幾句話就能夠解釋清楚的了。</p>
<p>我們先簡單介紹最基本的概念，後續再詳細專文介紹。</p>
<p>(1).htaccess檔案是Apache啟動後必須讀取的檔案，其位置看Apache設定。</p>
<p>(2)有時候有些設定也可以放在httpd.conf檔案下，但是httpd.conf只有在Apache啟動時讀取，而.htaccess是在每次連線都會去讀取。</p>
<p>(3).htaccess檔案內的某些宣告，必須配合先載入某些特定模組。例如你要進行URL的301轉址，就必須安裝mod_rewrite模組，才能在.htaccess內進行相關轉址宣告。</p>
<p>以下是.htaccess的幾個例子~</p>
<p>當你要阻擋某個ip連線進來，就可以宣告如下</p>
<p><span style="color: red;">deny from 46.28.160.1/32</span></p>
<p>以上的46.28.160.1/32，就是指ip 46.28.160.1不能連線進來，32是指其subnet mask (子網遮罩)是 255.255.255.255 (這個不懂沒關係)。</p>
<p>當你要進行轉址，就可以宣告如下</p>
<p><span style="color: red;"> RewriteEngine on<br />
RewriteCond %{HTTP_HOST}  ^dns.com.tw [nocase]<br />
RewriteRule ^(.*) http://www.dns.com.tw/$1 [last,redirect=301]<br />
</span></p>
<p>RewriteEngine on只需宣告一次，後面的各個轉址就不需要再寫一次。</p>
<p>哇，開始複雜了，上面的轉址就是說: 任何沒有www的URL，都要轉成有www開頭的URL，例如 http://dns.com.tw 會轉成 http://www.dns.com.tw，而 http://dns.com.tw/seo/ 會轉成 http://www.dns.com.tw/seo/</p>
<p>(4)怎麼辦? 這麼複製的語法根本搞不懂，沒關係，你可以使用<a href="http://www.htaccesseditor.com/tc.shtml" target="_blank">htaccess editor</a>，這個線上編輯可以簡便的操作一些常用的語法出來。</p>
<p>必須注意的是，許多.htaccess的語法的變化很多，很可能達成一個相同的任務，可以有許多不同的寫法。</p>
<p>如果對上述內容發現有不妥之處，歡迎大家提出討論囉。</p>The post <a href="https://seo.dns.com.tw/archives/6619">robots.txt與.htaccess檔案的用途是什麼?</a> first appeared on <a href="https://seo.dns.com.tw">SEO研究院</a>.]]></content:encoded>
					
					<wfw:commentRss>https://seo.dns.com.tw/archives/6619/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
