Ben Ward

Friendly URLs


Since I’m not adverse to regular expressions, I’ve tidied up the addresses for my blog posts.

Now, rather than an address that looks like “”, it looks like “”. Small change, but important because “index.php” means nothing, but “archives” (a naming convention that I’ve stolen from the rather popular Wordpress) does. The URL now bears some relation to accessing one of my historical blog posts.

With that small success in the bag, I’ve also smoothed out access to my XML feeds. The four XML syndication formats that b2Evolution provides (RSS, RSS 2, RDF and ATOM) can now be accessed via “”, “/read/rss2” for RSS version 2.0, “/read/rdf” for RDF format and “/read/atom” for an ATOM 0.3 feed.

Techie “HOWTO” bit…

Ultimately, this is user-friendly polish of the highest order and takes some of the pain out of the “one file to rule them all” nature of PHP programming.
You can achieve the same results (in b2Evolution) using the following Apache mod_rewrite rules. There’s still a lot of investigation that I need to do, not least because b2Evo does some URL rewriting of its own separately. That seems to be preventing me getting friendly-urls for my sub-blogs (my bookmarks list, for example).

“index.php” to “archive”
# Add this to your .htaccess file
# URL Rewriting for user-friendliness
RewriteEngine On
RewriteBase /

# Use "archive" rather than "index.php"
RewriteRule ^/?archive(\.php)?(.*)$ /index.php$2

Once this rule is in place, test it (go to “” and see if it goes to your homepage).

To get b2Evo to use this in the URLs that it generates, go into the preferences for your main Blog and set its ‘Stub Name’ to “archive” and choose the ‘Preferred access type’ as ‘Other blog through stub file’. Presto.

The (\.php) part of the above rule is a hack that prevents b2Evo breaking in places where it generates links with a .php extension (so generates “archive.php”). It’s not wonderfully pretty but it’s easier than modifying an unlimited quantity of b2Evolution’s source code.

XML Feed access

These ones don’t need any changes afterwards (note that they’re hard coded to my main blog (the number 2). I’ve made the choice that I’ll have to set up more rules for any other blogs that I want feeds for.

# XML Syndication Rewrites
RewriteRule ^/?xml/rss/?$ /xmlsrv/rss.php\?blog=2
RewriteRule ^/?xml/rss2/?$ /xmlsrv/rss2.php\?blog=2
RewriteRule ^/?xml/atom/?$ /xmlsrv/atom.php\?blog=2
RewriteRule ^/?xml/rdf/?$ /xmlsrv/rdf.php\?blog=2

RewriteRule ^/?read/rss/?$ /xmlsrv/rss.php\?blog=2
RewriteRule ^/?read/rss2/?$ /xmlsrv/rss2.php\?blog=2
RewriteRule ^/?read/atom/?$ /xmlsrv/atom.php\?blog=2
RewriteRule ^/?read/rdf/?$ /xmlsrv/rdf.php\?blog=2

As well as “/read/”, my feeds are also accessible through “/xml/”, for nerdier visitors.

Expect an update if/when I figure out how to get the bookmarks blog link working.


Previously, I hosted responses and commentary from readers directly on this site, but have decided not to any more. All previous comments and pingbacks are included here, but to post further responses, please refer me to a post on your own blog or other network. See instructions and recommendations of ways to do this.

  1. WD!

    I have one suggestion (although maybe I’m just going overboard now), but what about getting nice URIs for your category links? Like categories/general instead of archive?cat=19? That would be really cool!

    Anyway, keep up the good work. :-)

  2. Ben

    I think that’s an excellent idea. I must admit, I don’t use categories an awful lot – I’ve only got 4 and half the time I forget to select the right one when I post.

    I do think it would be nice to have though so I’ll have a look into writing some PHP (something like a getCategoryByName function). With that, it will require only a single mod_rewrite rule to implement (rather than one rule for each category which is more laborious in the long term).

    I think the eventual ideal would have to wrap up as much of the site in mod_rewrite as possible. I like the idea of having “/search/Friendly URLs” actually triggering a search for “Friendly URLs”, for example.

    Thanks very much for the suggestion.

You can file issues or provide corrections: View Source on Github. Contributor credits.