2012-02-19 99 views
1

谷歌的WMT工具看到我的網站爲2個不同的網站,所以我想實現301從非www到www重定向。主網站www.mysite.com使用Flash構建,包含wordpress博客的文件夾分別在www.mysite.com/blog/中保存。.htaccess在wordpress網站問題

在Wordpress文件夾中有一個.htaccess文件,下面的腳本看起來不正確,因爲有2個RewriteRules和RewriteCond條目。我應該刪除其中一個還是他們都需要?

爲什麼!-f和!-d在那裏 - 他們做了什麼?

也應該我的主要Flash站點有301自己的.htaccess文件非www到www?

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /blog/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /blog/index.php [L] 
</IfModule> 

回答

2
<IfModule mod_rewrite.c> 

RewriteEngine On 
RewriteBase /blog/ 

#If the file requested is index.php from the current folder(here: blog) 
#do not do anything 
RewriteRule ^index\.php$ - [L] 

#if other requests are not regular files or directories, 
#redirect it to /blog/index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /blog/index.php [L] 

</IfModule> 

不要刪除任何上述規則。他們很好,需要&。事實上,我建議你添加這個還有:

RewriteCond %{REQUEST_FILENAME} !-l 

rewritecond apache docs-f-d & -l是CondPatterns的變體。而非真正的正則表達式字符串。

  • 「-D」(是目錄) 黃柏TestString視爲一個路徑名並測試它是否存在,並且是一個目錄。
  • '-f'(是常規文件) 將TestString視爲一個路徑名,並測試它是否存在,並且是一個常規文件。
  • '-l'(是符號鏈接) 將TestString視爲一個路徑名,並測試它是否存在,並且是一個符號鏈接。

如果前綴爲感嘆號('!'),則會導致否定其含義。即!-f表示不是常規文件。


對於從non wwwwww網址重定向你.htaccessDocumentRoot使用:

RewriteEngine on 
RewriteBase/

RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^(.*)$ www.mysite.com/$1 [L,R=301] 
+0

感謝您解釋這些!只是要說清楚你是否應該使用2個.htaccess文件 - 每個根文件夾中有一個文件? – ubique 2012-02-19 15:08:49

+0

@ubique是的。但使用您在博客文件夾中的那個。還有我在你的documentroot中寫的那個。 – ThinkingMonkey 2012-02-19 15:25:33