WSN Gallery
Shortening URLs with mod_rewrite
Shortening URLs with mod_rewrite
By Paul

If you're on an Apache server, or a Windows IIS server with ISAPI Rewrite or another mod_rewrite compatiable facility, you can make your categories accessible by a simple yoursite.com/wsngallery/catname/ url (where catname is any category name), listing comments accesible by yoursite.com/wsngallery/thread/thread-name-1.html, and so on. This has the advantage of being friendlier-looking to the user, and it can put keywords in your URL which get you a better search engine rank.

To activate this option, simply go to Admin Panel -> Settings -> SEO and select to turn on url rewriting. If you've suppied your FTP info (at Settings -> System) everything from here should be handled automatically.

About the profile name rewriting option, please note: to do those rewrites, member names names must not contain special characters and must not be purely numeric. The registration page will automatically prevent illegal username registrations once you turn this on. This means it's only useful on English-language sites where people won't have accented or non-latin usernames.

Note:

  • When a category name contains a special character it cannot use name rewriting, since that's not a legal character for URLs. It'll fall back automatically on numeric rewriting for that category. Example characters that will cause this are commas, periods, apostrophes and accents. Note that if you use {CATID} in your rewrite scheme (like {CATREWRITEPATH}-{CATID}/{PAGE}.html) then it will continue to be able to uniquely identify the category so it won't have to fall back to numeric rewriting.
  • When you change the name of a category while using the category name URL rewriting, you'll need to regenerate categories before the subcategories list will update.
  • If you have other directories besides 'admin' beneth WSN Links that you'll need to access, you'll need to add htaccess rules to make them accessible rather than treated as categories. At Admin Panel -> Settings -> SEO -> "Other .htaccess Content", insert
    RewriteRule ^yoursubdirectory/?$ yoursubdirectory/index.php
    RewriteRule ^yoursubdirectory/([-_/\+A-Za-z0-9]+)/?$ yoursubdirectory/$1/index.php

    Change yoursubdirectory to the actual subdirectory, and .php to the applicable index file extension, and repeat for any other subdirectories. This auto-handles any nested directories below the first level.


Troubleshooting:

  • Subcategory URLs, last thread profile urls and the like are cached, and so when you change your rewriting they don't update until you regenerate.
  • If you've purposely blanked out one of the rewrite scheme boxes on the SEO settings page, that will kill everything. You must have a rewrite scheme in each box.
  • Some odd web hosts require that you remove the index Follow Sym Links line from the htaccess file.
  • The "Use top level category as subdomain?" option requires DNS wildcards, to have all subdomains redirected to your main (www) domain. You may need to talk to your web host to get this set up properly.


Some Example Supported Rewrite Formats:

For categories:
{CATREWRITEPATH}/{PAGE}.html
{CATREWRITEPATH}-{PAGE}.html


For details:
{IMAGEREWRITEPATH}/{IMAGETITLE}-{IMAGEID}.html
details/{IMAGETITLE}-{IMAGEID}.html


Recovery:

If you turn on rewriting but it doesn't work for whatever reason, you'll see an internal server error on your site. Delete your .htaccess file, then go to the SEO settings and turn rewriting off (or fix the issue).

Rating:


4.67/5 based on 3 votes. The median rating is 5.

Submitted: 09/30/03 (Edited 07/08/09)

Description: Details on how anyone running on an Apache web server can get keywords into URLs for SEO purposes.

Views: 6344 views. Averaging 3 views per day.
In the most recent 30 day period, there've been 12 views.

Previous Article

Features Showcase Purchase Services Resources Support