2011-02-03 105 views
1

我嘗試http://mydomain.com重定向到http://www.mydomain.com的.htaccess重定向不工作

我添加此我htaccess的文件,但它不工作:

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

這是一個完整的文件:

Options +FollowSymLinks +ExecCGI 

<IfModule mod_rewrite.c> 
    RewriteEngine On 

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

    # uncomment the following line, if you are having trouble 
    # getting no_script_name to work 
    #RewriteBase/

    # we skip all files with .something 
    #RewriteCond %{REQUEST_URI} \..+$ 
    #RewriteCond %{REQUEST_URI} !\.html$ 
    #RewriteRule .* - [L] 

    # we check if the .html version is here (caching) 
    RewriteRule ^$ index.html [QSA] 
    RewriteRule ^([^.]+)$ $1.html [QSA] 
    RewriteCond %{REQUEST_FILENAME} !-f 

    # no, so we redirect to our front web controller 
    RewriteRule ^(.*)$ index.php [QSA,L] 
</IfModule> 
+1

是否允許mod重寫? – 2011-02-03 09:39:18

+1

是的,我使用Symfony,並且我的網址正在重寫 – bahamut100 2011-02-03 11:43:57

回答

0

Try:

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

我現在在一個現有的網站上使用這個 - 似乎在這裏工作得很好。

0
# Never keep domain name without subdomain 
    RewriteCond %{HTTP_HOST} ^mydomain\.fr$ [NC] 
    RewriteRule ^(.*)$ http://www.mydomain.fr/$1 [R=301,L]