-2

I couldn't find the solution for "non-www" to "www" domain redirection. I have tried the following :

<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes

RewriteEngine on
RewriteBase /

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

# Remove index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

</IfModule>

So, how can I redirect, for example domain.com or www.domain.com to http://www.domain.com ?.

James C
  • 851
  • 1
  • 16
  • 34

6 Answers6

0

Something like should work :

<IfModule mod_rewrite.c>

  RewriteEngine on
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Lovau
  • 527
  • 2
  • 4
0

Here is what should help you:

RewriteEngine On
        RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
        RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
Guns
  • 2,598
  • 2
  • 19
  • 49
0

How To Create Temporary and Permanent Redirects with Apache click hear

To automatically add a www to your domain name:

  RewriteEngine On
   RewriteBase /
    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]

or

.htaccess To Redirect URLs

To use htaccess to redirect URL just copy and paste the snippet below and replace example.com with your domain.

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

More info true ans

Redirecting non-www to www with .htaccess

Community
  • 1
  • 1
Ravi Patel
  • 4,835
  • 2
  • 22
  • 42
0

Can you try this ?

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain.com
    RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
0

Seems apache mod_rewrite module is not enabled. So Make sure the Apache module mod_rewrite is enabled on your web server.

  • Everything that i gave on my htaccess is working other than this www part. Btw i am sure mod_rewrite module is enabled. – user3528662 May 09 '14 at 12:30
0

Try again this and see..It must work.

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain.com
    RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

See here - http://iyngaran.info, It is working. So no problem with the rule