Tuesday, July 24, 2012

htaccess redirect to www

To redirect a domain from a non www to a www domain, just add .htaccess


RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


to reverse redirect a domain from a www to a non www


RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]


Another way using the conf

redirect permanent / https://insert-url-of-your-site/

Example of using multiple url to point to the same site

  ServerName domain1.net
  DocumentRoot /opt/rlcache/www/moodle_prod
  Alias /sandbox /opt/rlcache/www/moodle_sand



  ServerName  domain2.net
  Redirect permanent / http://domain1.net/









No comments: