Skip to:
Content
Pages
Categories
Search
Top
Bottom

Nginx Rewrite Rules for Pretty Permalinks

  • On Nginx, I am using this for WordPress

    # WordPress pretty URLs: (as per dominiek.com)
    if (-f $request_filename) {
    break;
    }
    if (-d $request_filename) {
    break;
    }
    rewrite ^(.+)$ /index.php?q=$1 last;

    # Enable nice permalinks for WordPress: (as per Yawn.it)
    error_page 404 = //index.php?q=$uri;

    and I want something similar for bbPress. Please share the solution!

Viewing 10 replies - 1 through 10 (of 10 total)
  • There must be someone who is using bbPress on Nginx or maybe Sam can share!


    Sam Bauers
    Participant

    @sambauers

    This will probably work:

    rewrite ^/page/([0-9]+)/?$ /index.php?page=$1 last;
    rewrite ^/forum/([^/]+)/page/([0-9]+)/?$ /forum.php?id=$1&page=$2 last;
    rewrite ^/forum/([^/]+)/?$ /forum.php?id=$1 last;
    rewrite ^/forum/?$ / permanent;
    rewrite ^/topic/([^/]+)/page/([0-9]+)/?$ /topic.php?id=$1&page=$2 last;
    rewrite ^/topic/([^/]+)/?$ /bbpress/topic.php?id=$1 last;
    rewrite ^/topic/?$ / permanent;
    rewrite ^/tags/([^/]+)/page/([0-9]+)/?$ /tags.php?tag=$1&page=$2 last;
    rewrite ^/tags/([^/]+)/?$ /tags.php?tag=$1 last;
    rewrite ^/tags/?$ /tags.php last;
    rewrite ^/profile/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&page=$2 last;
    rewrite ^/profile/([^/]+)/([^/]+)/?$ /profile.php?id=$1&tab=$2 last;
    rewrite ^/profile/([^/]+)/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&tab=$2&page=$3 last;
    rewrite ^/profile/([^/]+)/?$ /profile.php?id=$1 last;
    rewrite ^/profile/?$ /profile.php last;
    rewrite ^/view/([^/]+)/page/([0-9]+)/?$ /view.php?view=$1&page=$2 last;
    rewrite ^/view/([^/]+)/?$ /view.php?view=$1 last;
    rewrite ^/rss/?$ /rss.php last;
    rewrite ^/rss/topics/?$ /rss.php?topics=1 last;
    rewrite ^/rss/forum/([^/]+)/?$ /rss.php?forum=$1 last;
    rewrite ^/rss/forum/([^/]+)/topics/?$ /rss.php?forum=$1&topics=1 last;
    rewrite ^/rss/topic/([^/]+)/?$ /rss.php?topic=$1 last;
    rewrite ^/rss/tags/([^/]+)/?$ /rss.php?tag=$1 last;
    rewrite ^/rss/tags/([^/]+)/topics/?$ /rss.php?tag=$1&topics=1 last;
    rewrite ^/rss/profile/([^/]+)/?$ /rss.php?profile=$1 last;
    rewrite ^/rss/view/([^/]+)/?$ /rss.php?view=$1 last;

    if ( !-e $request_filename ) {
    rewrite ^ /index.php last;
    }

    Thanks Sam! I will get back once I have tried them.

    I am sure that I am doing something wrong here.

    This is the vhost for the domain :

    server {

    listen 80;
    server_name mydomain.com;
    rewrite ^/(.*) http://www.mydomain.com/$1 permanent;

    }

    server {

    listen 80;
    server_name www.mydomain.com;

    access_log /home/public_html/mydomain.com/log/access.log;
    error_log /home/public_html/mydomain.com/log/error.log;

    location / {

    root /home/public_html/mydomain.com/public/;
    index index.php index.html;

    # Basic version of WordPress parameters, supporting nice permalinks.
    # include /usr/local/nginx/conf/wordpress_params.regular;
    # Advanced version of WordPress parameters supporting nice permalinks and WP Super Cache plugin
    include /usr/local/nginx/conf/wordpress_params.super_cache;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include /usr/local/nginx/conf/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /home/public_html/mydomain.com/public/$fastcgi_script_name;
    }
    }

    I have added the rewrite rules for bbPress in /usr/local/nginx/conf/bbpress_params.regular

    Now where should I add include /usr/local/nginx/conf/bbpress_params.regular; in my vhost file?


    punktoronto
    Member

    @punktoronto

    Has this been solved? I’ve been trying to figure it out as well. Everything I’ve found is for wordpress-mu and I’m not sure what needs to be changed to use it with regular wordpress.

    I found this http://insecure.no/2009/01/wordpress-and-bbpress-nice-url-rewrite-for-nginx/ it sort of works. pretty permalinks work but any attached files such as the css sheet or jquery.js returns a 404 not found error. Any Ideas?

    # SEO friendly URLs for bbPress

    #

    location /forums/ {

    root /path/to/YOURDIRECTORY/public_html/forums;

    index index.php;

    if (!-e $request_filename) {

    rewrite ^/forums/topic/(.*)$ /forums/topic.php?q=$1 last;

    rewrite ^/forums/forum/(.*)$ /forums/forum.php?q=$1 last;

    rewrite ^/forums/profile/(.*)$ /forums/profile.php?q=$1 last;

    rewrite ^/forums/view/(.*)$ /forums/view.php?q=$1 last;

    rewrite ^/forums/tags/(.*)$ /forums/tags.php?q=$1 last;

    rewrite ^/forums/rss/(.*)$ /forums/rss.php?q=$1 last;

    rewrite ^/forums/bb-admin/ /forums/bb-admin/index.php last;

    rewrite ^/forums/ /forums/index.php last;

    break;

    }

    }

    Nope. Its a pending issue of mine. May be we can get a response now.

    BUMP!

    These rewrites posted are correct. This is pretty much what we have.

    Our environment is very different and we have a few in-house modules to handle ‘missing files’ in place of the ‘!-e’.

    As far as the rewrites go they’re good, and obviously you must enable pretty perms for bbpress.

    If your having problems ashfame, just cut/past the rewrites outside the file check conditional (if).

    @Jason

    The issue is that I don’t know where to add those. Read this post.

    As soon as I add the include line like

    locations /forums/
    {
    include ...
    }

    even my WP stops working.

    I have WP running at / and bbPress at /forum/.

    This is the configuration I’m using:

    http://gist.github.com/770180

    Note that there was an error in one of the rules Sam posted:

    rewrite ^/topic/([^/]+)/?$ /bbpress/topic.php?id=$1 last;

    should have been

    rewrite ^/topic/([^/]+)/?$ /topic.php?id=$1 last;

    Thanks Scribu! Handy thing.

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.
Skip to toolbar