How to Redirect Your Elgg Site from mydomain.com to www.mydomain.com

There has been a lot of discussion on how to safely redirect an Elgg address when the “www” part of the url is omitted.  There is a lot of documentation on how to do this directly in the .htaccess file. However, any wrong modification could hurt your Elgg site and make it unaccessible. In this article, I will give you step by step guide on how to  redirect your Elgg site from mydomain.com to www.mydomain.com

1. First, go to YourElggFolder/views/default/page_elements and open the file header.php

2. Add this code at the top, after the <?php tag:

if($_SERVER['SERVER_NAME']==”mydomain.com”)

{header( ‘Location: http://www.mydomain.com’);
exit;}

if($_SERVER['SERVER_NAME']==”mydomain.com”){header( ‘Location: http://www.mydomain.com’);exit;}

3. Save it. Now try to access your site without the “www” part in the url. You will see that it automatically redirects to the site with the complete url. If you are using a custom theme, do the same process, but instead, go to the header.php file of the custom theme.

This concludes how to redirect your Elgg site from mydomain.com to www.mydomain.com

Looking for quality Elgg Hosting? Check out Arvixe Web Hosting.

Happy Hosting!

Rodolfo Hernandez

Tags: , , , , , , | Posted under Elgg | RSS 2.0

Author Spotlight

Rodolfo Hernandez

Rodolfo Hernandez

I like photography and reading books. Currently working for Arvixe as Elgg Community Liaison. Elgg Security Expert Web Security Expert CEO of UDP SW Social Web

Leave a Reply

Your email address will not be published. Required fields are marked *


× 8 = 48

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>