views:

80

answers:

2

Hello

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

+2  A: 
RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^.*$ http://www.example.com/$0 [NC,L,R=301]
Álvaro G. Vicario
+4  A: 

Try this mod_rewrite rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Gumbo
note: this will also redirect something.example.com to www.example.com
Piskvor
@Piskvor: No, it will redirect it to *www.something.example.com*.
Gumbo
Thanks for the reply. But what does i means R=301?
@basit74: The *R* flag forces an external redirect and *301* is the status code of the response.
Gumbo
@Gumbo: I stand corrected.@basit74: R=301 means HTTP Redirect with code 301 (Moved Permanently).
Piskvor