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,402
  • 16
  • 64
  • 91
user160820
  • 14,866
  • 22
  • 67
  • 94

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
  • 643,351
  • 109
  • 780
  • 844
2
RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^.*$ http://www.example.com/$0 [NC,L,R=301]
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
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