Monday, 8 April 2019

Removing "www" through an .htaccess file

Removing "www" through an .htaccess file

To automatically remove the www from the beginning of your domain, add the following mod_rewrite rule to your .htaccess file. If you don't have that file, create it in a text editor and then upload it to your root directory:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Forcing the ‘www’ subdomain in an .htaccess file

To force the use of "www" when viewers are reading your site, you can use the following remove link mod_rewrite rule in your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST}  !^www\.example\.com$ [NC]
RewriteRule ^(.*) http://www.example.com/$1 [L,R]
If someone types in example.com, the URL now change to www.example.com.

No comments:

Post a Comment