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/wsnlinks/catname/ url (where catname is any category name), listing comments accesible by yoursite.com/wsnlinks/catname/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 supplied your FTP info (at Settings -> System) everything from here should be handled automatically.

Notes:

  • When a category name contains a special character like an apostrophe 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.
    Sub-Note 1: You can work around this problem by editing the category to type in a special URL for it manually which will override the normal rewrite rules.
    Sub-Note 2: If you use {CATID} in your rewrite scheme (like {CATREWRITEPATH}-{CATID}/{PAGE}.html) then it will 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 may need to regenerate categories before the subcategories list will update (though in most situations it should update automatically).
  • If you remove {MEMBERID} from the profile rewrite scheme, member names names must then not contain special characters and must not be purely numeric. The registration page will automatically prevent illegal username registrations once you make this change. This means it's only useful on English-language sites where people won't have accented or non-latin usernames.


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 09/12/10)

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

Views: 7207 views. Averaging 2 views per day.
In the most recent 30 day period, there've been 13 views.

Previous Article | Next Article

Features Showcase Purchase Services Resources Support