Support > Knowledge Base > Web Hosting > Web Sites > How to redirect URL without WWW to URL with WWW using .htaccess

How to redirect URL without WWW to URL with WWW using .htaccess

How to redirect URL without WWW to URL with WWW using .htaccess.

Create a .htaccess file with content in frame bellow and upload it to server. This will redirect URLs without www to URLs with www. This rewrite rule also remains http/https and absolute path after hostname.

[ISAPI_Rewrite]
 
RewriteEngine on
 
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301]

Applies To

IIS, Web server, Web site, URL Rewriter

See Also

How to use .htaccess and .htpasswd configuration files

Page views: 406