Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting URL without www to www

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.

like image 259
user160820 Avatar asked Feb 16 '10 10:02

user160820


2 Answers

Try this mod_rewrite rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
like image 139
Gumbo Avatar answered Sep 18 '22 17:09

Gumbo


RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^.*$ http://www.example.com/$0 [NC,L,R=301]
like image 27
Álvaro González Avatar answered Sep 18 '22 17:09

Álvaro González