Force www./no-www. in .htaccess

/ Published in: Bash
Save to your folder(s)

This example shows you how to force www. or no-www. using .htaccess file.

Copy this code and paste it in your HTML
  1. # Force the www.
  2. RewriteEngine On
  3. RewriteCond %{HTTP_HOST} ^ [NC]
  4. RewriteRule ^(.*)$$1 [L,R=301]
  6. # Remove the www.
  7. RewriteEngine On
  8. RewriteCond %{HTTP_HOST} !^$ [NC]
  9. RewriteRule ^(.*)$$1 [L,R=301]


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.