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!