Search Engine Friendly URLs

Enabling search engine friendly URLs

Configuring Pixaria Gallery

Search engine friendly URLs in Pixaria can be turned on in the General Settings control panel under the 'Features' tab. This feature should work 'out of the box' in most cases but in the event that you experience problems, there is a detailed guide to the feature included below.

All you have to do to enable this feature is to tick the checkbox to turn search engine friendly URL support on and then save the changes.


Guide to search engine friendly URLs

What is Mod_Rewrite?

First off, if you don't have Apache installed as the web server daemon on the computer where Pixaria Gallery is hosted, then this tutorial is not for you. Mod_Rewrite is a very powerful module for the Apache web server that allows you to do complex, rule based URL redirections to dynamically control how a web browser accesses resources on your web server.

This part of the documentation is not intended to provide a guide to using Mod_Rewrite because there are plenty of guides out there that will do a much better job of it than I can! The best place to begin if you're looking for more information is Google.

What does Mod_Rewrite do for Pixaria Gallery?

Query strings and complex URLs

If you've already got Pixaria Gallery up and running on your server, you'll probably have noticed that lots of the URLs for images and albums are complex, long lines of text with question marks, ampersands, equals signs and other bits and pieces in them. These types of URLs are interpreted by Pixaria Gallery as a means of transferring information between pages without the need for submitting a form.

For example, the following code after the end of a normal URL for a PHP script like 'index.php' will tell the script that there is a new variable to use called 'id' with the value of '300': ?id=300. It's possible to pass lots of variables into a PHP script by building chains of these so-called query strings with each variable name and value separated by an ampersand (&) sign.

As you will no doubt have noticed, these complex strings of variables in a URL make it virtually impossible to remember an exact URL for an image in Pixaria Gallery but there is a more serious consequence in that these URLs are almost never indexed by search engines. The reason for this is that most search engine spiders will correctly assume that a link containing a query string is a link to a dynamic page i.e. one that will have different content depending on the variables passed in the query string.

This is obviously a bad thing if you want search engine spiders to index your site so people can find your images.

How can we avoid using query strings

There are two ways of avoiding using query strings:

  1. Don't use dynamic links and pages
  2. Make fake non dynamic links that are really pointers to dynamic links and pages

The first solution, while simple for small sites, is really not at all practical for a script like Pixaria Gallery where there are potentially hundreds or thousands of images each needing their own separate page. Some scripts get around this by outputting real HTML pages with static links so the pages are not generated dynamically at all. This is a fairly good solution but it means that whenever the site is changed, all the pages have to be created again which is time consuming and demanding on the serve, particularly with respect to storage space.

The second solution is much better but is a little more complex to implement...

Mod_Rewrite to the rescue

Mod_Rewrite is the key to this solution and while most web servers using Apache to serve pages support it, some don't. For this reason, it's not always possible to use this technique with all web servers and hosting packages.

To describe what Pixaria Gallery can do with Mod_Rewrite is quite simple:

Basically, it becomes possible to make a static URL like:

'http://www.pixaria.com/gallery/2345'

Point, internally, to a dynamic URL like:

'http://www.pixaria.com/index.gallery.php?gid=2345'

This means that the user (or search engine spider) thinks the page is static when in fact is isn't. At no point will the user be aware that the URL in the address bar of their web browser ('http://www.pixaria.com/gallery/2345') is actually a PHP script. Since all the URL rewriting is done on the web server the process is transparent and it becomes possible to have an unlimited number of fake URLs that all get translated into requests for a script.

Set-up mod_rewrite using a .htaccess file

Before you begin, it's important to check to see if there are is a .htaccess file already on your server - beware that some FTP programs and servers hide these from view which means that it's possible to accidentally overwrite a file that was already there and potentially mess up your server configuration.

To set-up Pixaria 2.0 to use search engine friendly URLs using .htaccess, you should use the following code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.*) index.php
</IfModule>

Note: If your Pixaria Gallery installation is in a subdirectory of your main website, e.g. http://www.mysite.com/subdirectory/, you may need to add a RewriteBase directive replacing the word 'subdirectory' with the name of the directory where Pixaria is installed.

<IfModule mod_rewrite.c>
RewriteBase /subdirectory/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.*) index.php
</IfModule>

Troubleshooting Mod_Rewrite

If you find that Mod_Rewrite is not working correctly after applying your .htaccess file settings, it is possible that Mod_Rewrite is not enabled on your server or that there is a mistake in the text you've put into your .htaccess file.

How to activate Mod_Rewrite on Apache

Please note that editing the files described here can cause your website to fail completely if you don't know what you're doing and make a mistake. You follow these set-up instructions entirely at your own risk, so please make back-ups and if in doubt, don't do anything!

Before you can use Mod_Rewrite with Pixaria Gallery, your Apache web server may need configuring to enable it to integrate with the requirements for URL rewriting in Pixaria Gallery.

It's very important that the mod_rewrite module for Apache is installed and loaded before you try to set-up any mod_rewrite directives. If it isn't then Apache will not run correctly and your website will not be available. For this reason, I recommend consulting your hosting company or system administrator about using Mod_Rewrite before you begin making the changes in this tutorial.

Mod_Rewrite can usually be enabled in httpd.conf by uncommenting these lines:

In Apache 1.x

#LoadModule rewrite_module /usr/lib/apache/mod_rewrite.so
#AddModule mod_rewrite.c

Like this:

LoadModule rewrite_module /usr/lib/apache/mod_rewrite.so
AddModule mod_rewrite.c

In Apache 2.x

#LoadModule rewrite_module /usr/lib/apache/mod_rewrite.so

Like this:

LoadModule rewrite_module /usr/lib/apache/mod_rewrite.so
AddModule mod_rewrite.c

Note that these entries don't usually appear on lines next to each other like this in the actual config file and the paths shown may differ depending on how your server is configured and what operating system it uses.




Last edited on Tuesday July 17 2012 at 05:54:30

Search Pixaria Documentation

You can search the Pixaria documentation by entering keywords here. Keep your search simple for the best results.