Force www.MyDomain.com or without www (MyDomain.com) in a URL

Force www.MyDomain.com or without www (MyDomain.com) in a URL

I would like to force my sites to show www.MyDomain.com
or to show without www. How can I do this? This is easily done with our
linux servers by using the following .htaccess directives. .htaccess is
a regular text file that can be created in the file manager located in
your control panel or by uploading a text file. .htaccess tells the web
server to use the directives that is in it. Force www:
 
#Force WWW in address bar
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


Force Without WWW
 
#Force Without WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    • Related Articles

    • CPanel URL Tweak Settings

        Note: When a user accesses cPanel, WHM, or Webmail on an SSL/TLS port with the HTTP protocol, the web server redirects the user to the URL of the server's hostname with the HTTPS protocol. For example, if the server's hostname ...
    • Redirect non www domain to www in classic asp

      If you are running your site on classic .asp, on a IIS 6 web server. Here is a method you can use to forward all non www. requests to www.example.com. Create a new file for example named: redirect.asp | and insert this code into the file redirect.asp ...
    • SSL certificate not valid for domain.com but is for www.domain.com or vice versa

      Problem 1: I have purchased an SSL for domain.com, however, www.domain.com gives an SSL error Problem 2: I have purchased an SSL for www.domain.com, however, domain.com gives an SSL error -------------------------------- Most SSLs will provide a ...
    • How to force HTTPS using the .htaccess file

      To force all web traffic to use HTTPS - insert the following lines of code in the .htaccess file in your website's root folder. Important:If you have existing code in your .htacess, add this above where there are already rules with a similar starting ...
    • How to Setup URL Redirection (Hsphere)

      You can use this function in Hsphere to redirect your visitors from one domain's web page to another, or to a completely different domain name. To create a redirect do the following: 1. Login to hsphere control panel. 2. Go to "Quick Access" on the ...