RyanTAdams.com

Technology Advice by Ryan Taylor Adams

My Gallery2 Website Doesn’t Work When “www.” is Prefixed to My Domain

December 17th, 2007 · 2 Comments · Printer Friendly Version

WARNING! THIS POST IS MORE THAN 180 DAYS OLD!

While I make an effort to update older posts to keep them relevant and technically accurate, the rapidly changing nature of the tech world makes it possible that the content of this post may no longer be relevant, current, or even accurate. Additionally, because of this post's age, adding new comments has been disabled. If you would like to contribute new information to this post, or have questions pertaining to this post, please use the Contact Form.


I’ve just finished moving my old Gallery2 (picture management system based on PHP) installation to a new server. For some reason, viewing said gallery using http://www.gallery.ryantadams.com worked, whereas using http://gallery.ryantadams.com (notice no “www.”) would prevent any of my pictures from being displayed. I searched the Gallery2 support forums, but there were only a few related posts, and none had been resolved. I came up with the following solution, which seems to work but has not be thoroughly tested:

First, if you have the URL Rewrite plugin installed, or have ever used it, make sure it is still installed and activated. You will however have to uncheck all the rules. This basically means the plugin is installed and active, but not rewriting any URLs.

Once that is done, open the .htaccess file in the root folder of the Gallery2 installation. By default this folder is called “Gallery2,” but you may have renamed it.

You need to edit the file to look like so:


RewriteEngine On
   RewriteCond %{HTTP_HOST} !www.gallery.ryantadams.com
   RewriteRule ^.*$ http://www.gallery.ryantadams.com%{REQUEST_URI} [R]
#{gallerySection}

Obviously change any references to my gallery to yours.

Now test it out. Going to http://yourgallery.com should automatically redirect you to http://www.yourgallery.com.

Be sure to go into the Gallery maintenance section and and run the scripts to delete any caches and also to optimize the database.

If you want to use the URL Rewrite plugin, try re-enabling each one of its options now, one by one, verifying your site still works after each time. If you didn’t use, or don’t want to use the URL Rewrite plugin, you’re done!

If this solution works for you, or if you have anything to add, please leave a comment.

2 responses so far ↓

  • 1 Chris Lee // Jan 11, 2008 at 7:09 AM


    Thanks! It’s work!

  • 2 dublin // Sep 29, 2008 at 6:57 AM


    works for me too. better to post the website without the www, but more practical to deal with cookies when there is the www, Thanks a lot!