2012-10-04 34 views
0

可能重複:
apache redirect from non www to www非www到www .htaccess重定向不工作?

我想我的域名重定向非www到WWW版本。出於某種原因,下面的代碼不起作用。

有什麼建議嗎?

最可能的任何簡單的修復,但我不能得到它的工作。

<ifmodule mod_deflate.c> 
<filesmatch \.(css|html|js|php|xml)$> 
    setoutputfilter deflate 
</filesmatch> 
</ifmodule> 
<ifmodule mod_security.c> 
secfilterengine off 
secfilterscanpost off 
</ifmodule> 

<ifmodule mod_rewrite.c> 
    RewriteEngine on 
RewriteCond %{HTTP_HOST} ^trailerpulse.com/ 
RewriteRule (.*) http://www.trailerpulse.com/$1 [R=301,L] 
RewriteCond %{request_filename} -f 
RewriteRule ^(.*) $1 [L] 
RewriteRule ^([a-z]+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L] 

</ifmodule> 
<ifmodule mod_expires.c> 
ExpiresActive On 
ExpiresDefault A0 
<filesmatch \.(css|js|gif|jpe?g|png)$> 
    ExpiresDefault A604800 
</filesmatch> 
<filesmatch \.(html|xml)$> 
    ExpiresDefault A10800 
</filesmatch> 
</ifmodule> 

FileEtag None 
Options All -Indexes 
ServerSignature Off 
ErrorDocument 404 /error 
+0

你爲什麼要使用mod_rewrite是什麼? http://stackoverflow.com/questions/1100343/apache-redirect-from-non-www-to-www/1100363#1100363 –

+0

這是代碼的寫法,當我購買了該網站的基礎的腳本。 – Rhys

+0

夠公平的。我建議轉向使用在那個鏈接問題中提到的'Redirect'指令,這很簡單。 –

回答

0

你的規則幾乎就在那裏。唯一的問題是在主機名後面有一個斜槓,從不出現在請求的「主機:」標頭中。與$更換/並添加[NC]標誌忽略大小寫:

RewriteCond %{HTTP_HOST} ^trailerpulse.com$ [NC] 
RewriteRule (.*) http://www.trailerpulse.com/$1 [R=301,L]