- RyanTAdams.com - //blog.ryantadams.com -

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

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 //www.gallery.ryantadams.com worked, whereas using //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 ^.*$ //www.gallery.ryantadams.com%{REQUEST_URI} [R]

Obviously change any references to my gallery to yours.

Now test it out. Going to //yourgallery.com should automatically redirect you to //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.