1

I try to redirect http://mydomain.com to http://www.mydomain.com

I add this to my htaccess file, but it not work :

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

This is the complete file :

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>
bahamut100
  • 1,795
  • 7
  • 27
  • 38

2 Answers2

0

Try:

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

I'm using this on an existing site at the moment - seems to work fine here.

richsage
  • 26,912
  • 8
  • 58
  • 65
  • You're going to need to be a bit more specific than "it doesn't work". Have you checked Apache logs? What do they say? We're going on not much information here... – richsage Feb 03 '11 at 17:24
0
  # Never keep domain name without subdomain
  RewriteCond %{HTTP_HOST} ^mydomain\.fr$ [NC]
  RewriteRule ^(.*)$ http://www.mydomain.fr/$1 [R=301,L]
JeremyK
  • 3,240
  • 1
  • 11
  • 24