.htaccess重定向无法正常工作

时间:2011-02-03 09:34:27

标签: .htaccess symfony1

我尝试将http://mydomain.com重定向到http://www.mydomain.com

我将此添加到我的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>

2 个答案:

答案 0 :(得分:0)

尝试:

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

我现在在现有网站上使用它 - 似乎在这里工作正常。

答案 1 :(得分:0)

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