htaccess redirects
htaccess redirects
  [ Enlarge Image ]  
 
 
<< Back 
Posted: 2007/05/23 by: fcruz. Linux - Unix Blogs.
The following is an example of how to redirect your complete site to the domain name without the www or viceversa.

In some cases you might need to redirect your complete site from www.yoursite.com to yoursite.com , using htaccess on a linux environment with Apache web server this can be achieved with the following directive:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]

In the opposite case you might need to redirect yoursite.com to www.yoursite.com

The following directive will do it:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]

For such directives to work make sure htaccess directives are enabled on the apache config.

Cheers
Felipe Cruz






[ Back ]