Latest Register Log In

+ Advanced Search

SEO URLs with mod_rewrite

SEO URLs with mod_rewrite
By
09/30/03 (Edited 03/10/14)

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/wsn/catname/ url (where catname is any category name), listing comments accesible by yoursite.com/wsn/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.

Notes:

  • Only a handful of formats are supported, you can't set an arbitrary rewrite format and expect it to work. Contact support if you need a format that isn't supported.
  • 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 ({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. If this is the case for you, go to Admin -> Settings -> Tweaks Editor and turn on the nofollowsymlinks tweak.
  • The "Use top level category as subdomain?" option requires DNS wildcards, to have all subdomains redirected to your main (www) domain. You will need to talk to your web host to get DNS wildcards set up, they will not be set up by default.

Some Simple Example Supported Rewrite Formats

For categories:

{CATREWRITEPATH}/{PAGE}.html
{CATREWRITEPATH}-{PAGE}.html


For details:
{LINKREWRITEPATH}/{LINKTITLE}-{LINKID}.html
details/{LINKTITLE}-{LINKID}.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 Admin -> Settings -> SEO to fix the issue if the issue is a bad format (or turn rewriting off if you can't fix it).





Description Details on how anyone running on an Apache web server can get keywords into URLs for SEO purposes.
Rating
Views 8340 views. Averaging 2 views per day.