5

I need your help. I want to test if the URL is entered without www

like example.com it should be forwarded to www.example.com.

Bitmap
  • 12,035
  • 15
  • 62
  • 89
user160820
  • 14,296
  • 21
  • 61
  • 92

3 Answers3

12

Try this mod_rewrite rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Gumbo
  • 620,600
  • 104
  • 758
  • 828
2
RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^.*$ http://www.example.com/$0 [NC,L,R=301]
Álvaro González
  • 135,557
  • 38
  • 250
  • 339
2

If you are using nginx, then add this line to nginx config:

server {
  listen 80;
  server_name yourdomain.com;
  rewrite ^/(.*) http://www.yourdomain.com/$1 permanent;
}
Lemon
  • 21
  • 2