Knowledge Base » Blog Archive » Redirect all requests to (or non-www)

Redirect all requests to (or non-www)

August 4th, 2016

Redirecting your website from non-www to www URLs can be as simple as adding suitable code in your .htaccess file.

For non-WordPress websites, you can use the code below replacing with your own domain name.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$$1 [R=301,L]

For WordPress websites, this should be done by setting the URLs in your WordPress General Settings. Using the code above for a WordPress website can put it in a loop.

You can also force non-www URLs in a similar way by changing the code as follows. Again, this should be placed in your .htaccess file located in your public_html folder.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domainname\.com [NC]
RewriteRule ^(.*)$$1 [L,R=301]