How can I rewrite the URL to the www or non-www version so visitors will only go to that URL?

Use one of the following in .htaccess to rewrite the URL:

#Non-WWW to WWW version:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

#WWW to non-WWW version:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.domain.com [nc]
rewriterule ^(.*)$ http://domain.com/$1 [r=301,nc]

Please be aware that URLs are also set in scripts such as Wordpress or Joomla in their databases, admin sections, or config files which may need to be edited.
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How do I turn Directory Indexing off?

Add the following to .htaccess:Options -IndexesTurn it back on:Options +Indexes 

How can I setup dynamic/custom error pages?

If you have defined your own custom Error Pages using the "Define Error Pages" tool within the...

How do I do a rewrite instead of a 302 for missing pages?

Use something like this:RewriteEngine onRewriteCond %{REQUEST_FILENAME} !index.htmlRewriteRule /*...

How do I stop off-line browsers/ robot surfers?

Try the following in .htaccess:RewriteEngine OnRewriteCond %{HTTP_USER_AGENT} ^MozillaRewriteRule...

How do I prevent spam from email harvestering?

Use the following in .htaccess:RewriteEngine onRewriteCond %{HTTP_USER_AGENT} ^Bullseye.*...