Advanced search

Rewrite rules for Pretty URLs

If you want to use Pretty URLs, the configuration is a two step process. First, you must setup your web server to perform the necessary URL rewriting. For EoS that's actually pretty easy, because all requests are routed through index.php, so a single rewrite rule should be sufficient.

Note that it is absolutely crucial to set up URL rewriting properly. Failing to do so can make your forum unaccessible, the admin panel, however should always work, because admin URLs are never using the pretty format.

Rewrite rules will not stop non-pretty URLs from working. EoS only uses pretty URLs for a couple of things like topics, boards, member profiles but not everywhere. Here are example rewrite rules for two of the most popular web servers, Apache and nginx. These are only examples though, pretty URLs should be able to work with any web server that supports simple URL rewriting.

For nginx

Code: php
// this assumes, your forum URL is http://your.doamin/forum/
// you need to modify this if your forum resides in the root or different folder!
location /forum/ {
  if (!-e $request_filename) {
    rewrite ^/forum/(.*)$ /forum/index.php?q=$1 last;

For Apache

Code: php
// assuming, forum URL is something like http://your.domain/
// if not, adjust RewriteBase
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

For lighthttpd

(contributed by Valodim)
Code: php
  url.rewrite-if-not-file += (
    "^/forum/([^?]*)$" => "/forum/index.php?q=$1",

How to figure out whether rewrite rules are working

One method is to request some URL that doesn't exist on your forum. For example, assuming your forum is hosted on http://my.comain.com/forum/, browse to http://my.comain.com/forum/profile/member-1 and you should see the profile page of the member with the user id 1 (normally your own profile, or the profile of the admin who installed the forum), instead of seeing a 404. This is because our rewrite rule tells the web server to rewrite all requests to index.php and append the original query string as a parameter (q). The rewritten request would then be http://my.comain.com/forum/index.php?q=/profile/member-1 which is a valid pretty URL and will be translated by the pretty URL parser into the final URL http://my.comain.com/forum/index.php?action=profile;u=1

If you see the profile page, chances are your rewrite rules are working. If you don't see the proper page, your rewriting is not working and you need to begin troubleshooting it. The easiest (and most successful) way is to enable rewrite logging on your web server. I'm not going into detail here (just google it) how to do this, but once set up, the logs will tell you exactly what your web server is doing and how it rewrites the URLs.

Side note

These rewrite rules should also work for SMF with the SimpleSEF modification providing the pretty URL format, because EoS Alpha is using an identical URL format. Just in case, google sent you here...

Last modified: Tuesday, July 31, 2012 at 15:53 CET, by Nightwish

Category: EoSAlpha

Page generation time: 0.099 seconds