Nginx and Wordpress htaccess url conversion

Steve steven.romej at
Wed May 9 05:18:30 MSD 2007

Wordpress ships with a seemingly simple set of htaccess rules to implement its
url scheme.  I browsed this list and saw some tips for setting up Wordpress MU
but I couldn't find a direct translation of the following rewrite rules to the
Nginx format.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
# END WordPress

Here's my current mess.  I'm trying to run the PHP-based blog off the /blog/
directory.  The / directory will contain a Rails app.  Not sure if I'm going
about that correctly either.

location /blog/ {
   root html/;
   index index.php;
   #if ( !-e $request_filename ) {
   #  rewrite ^/blog(.*)[^/]$ /blog$1/ break;
  if ( !-e $request_filename ) {
       rewrite ^([0-9a-zA-Z]+)?(/wp-.*) $2 break;
       rewrite ^([0-9a-zA-Z]+)?(/.*\.php)$ $2 last;
       rewrite ^ /blog/index.php last;
  #if ( !-e $request_filename ) {
  #  rewrite ^/blog/(.*)$ /blog/index.php/$1 break;

Thank you for your help!

More information about the nginx mailing list