Skip to content
Sri Lanka · Colombo · GlobalMon–Fri, 09:00–18:00 IST
Web Design 1 min read

Redirecting non-www to www with .htaccess

If you want to redirect all non www requests to your web site to the www version, all you need to do is add the following code to your .htaccess file: Needless to say that you must be running on apache with mod_rewrite enabled. RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ htt...

A
Written by
Admin
18 views
Share:
If you want to redirect all non www requests to your web site to the www version, all you need to do is add the following code to your .htaccess file: Needless to say that you must be running on apache with mod_rewrite enabled.
RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Redirecting www to non-www 
RewriteEngine On RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC] RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]
Share:

Related Articles

Comments (0)

Log in or sign up to leave a comment.

No comments yet. Be the first to share your thoughts!