Rewrite rules for nginx webserver (and phpbb seo)

Discussions and support about the different URL Rewriting techniques for phpBB.

Moderator: Moderators

Rewrite rules for nginx webserver (and phpbb seo)

Postby intel352 » Thu Sep 24, 2009 10:32 pm

Just migrated to a new server, installed nginx.

It's been a good learning experience, and I can't say enough about this webserver software, it's awesome :-)

Anywho, to help others moving into nginx, here's my site config file for my forum.
Please note, this is for a version of phpbb-seo that I installed roughly a year ago. dunno if anything has changed in the rewrite rules in the current release(s), but maybe this will at least give a starting point for others.

Code: Select all
server {
        listen   67.23.21.55:80;
        server_name forum.phpsitesolutions.com;

        root   /var/www/forum.phpsitesolutions.com/public/phpbb2/;
        index  index.php index.html;
        fastcgi_index  index.php;

        access_log /var/www/forum.phpsitesolutions.com/log/access.log;
        error_log /var/www/forum.phpsitesolutions.com/log/error.log warn;

        # if the request starts with our frontcontroller, pass it on to fastcgi
        location ~ \.php
        {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }

        location / {
                # PHPBB SEO REWRITE RULES - ADVANCED
                # AUTHOR : dcz www.phpbb-seo.com
                # STARTED : 01/2006

                # FORUM
                rewrite ^/[a-z0-9_-]*-f([0-9]+)/?(page([0-9]+)\.html)?$ /viewforum.php?f=$1&start=$3 last;

                # TOPIC WITH VIRTUAL FOLDER
                rewrite ^/[a-z0-9_-]*-f([0-9]+)/[a-z0-9_-]*-t([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?f=$1&t=$2&start=$4 last;

                # GLOBAL ANNOUNCES WITH VIRTUAL FOLDER
                rewrite ^/announces/[a-z0-9_-]*-t([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?t=$1&start=$3 last;

                # TOPIC WITHOUT FORUM ID & DELIM
                rewrite ^/([a-z0-9_/-]*)/?[a-z0-9_-]*-t([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?forum_uri=$1&t=$2&start=$4 last;

                # PROFILES THROUGH USERNAME
                rewrite ^/member/([^/]+)/?$ /memberlist.php?mode=viewprofile&un=$1 last;

                # USER MESSAGES THROUGH USERNAME
                rewrite ^/member/([^/]+)/(topics|posts)/?(page([0-9]+)\.html)?$ /search.php?author=$1&sr=$2&start=$4 last;

                # GROUPS ADVANCED
                rewrite ^/[a-z0-9_-]*-g([0-9]+)(-([0-9]+))?\.html$ /memberlist.php?mode=group&g=$1&start=$3 last;

                # POST
                rewrite ^/post([0-9]+)\.html$ /viewtopic.php?p=$1 last;

                # ACTIVE TOPICS
                rewrite ^/active-topics(-([0-9]+))?\.html$ /search.php?search_id=active_topics&start=$2&sr=topics last;

                # UNANSWERED TOPICS
                rewrite ^/unanswered(-([0-9]+))?\.html$ /search.php?search_id=unanswered&start=$2&sr=topics last;

                # NEW POSTS
                rewrite ^/newposts(-([0-9]+))?\.html$ /search.php?search_id=newposts&start=$2&sr=topics last;

                # THE TEAM
                rewrite ^/the-team\.html$ /memberlist.php?mode=leaders last;

                # HERE IS A GOOD PLACE TO ADD OTHER PHPBB RELATED REWRITERULES

                # FORUM WITHOUT ID & DELIM
                # THESE THREE LINES MUST BE LOCATED AT THE END OF YOUR HTACCESS TO WORK PROPERLY
                if (!-e $request_filename) {
                        rewrite ^/([a-z0-9_/-]+)/?(page([0-9]+)\.html)?$ /viewforum.php?forum_uri=$1&start=$3 last;
                        break;
                }
                # END PHPBB PAGES
        }
}
intel352
 
Posts: 6
Joined: Sun Aug 03, 2008 8:45 am

Advertisement

Re: Rewrite rules for nginx webserver (and phpbb seo)

Postby dcz » Sun Sep 27, 2009 1:42 pm

Interesting, so apart from slashes and flags, rewriterules are basically the same as with Apache. Our mod rewrite's .htaccess have changed a bit since the last version, since all modes have been unified, but the same principle should still work.

We should think one day about making our .htaccess generator to generate more than .htaccess for other servers ;)
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21325
Joined: Fri Apr 28, 2006 9:03 pm

Re: Rewrite rules for nginx webserver (and phpbb seo)

Postby IPB_Refugee » Mon Mar 29, 2010 12:49 pm

Hello intel352,

thanks a lot!

I'm also thinking about moving to nginx as my Apache installation suffers from some severe memory leak.

It's good to know that I still will be able to use this fine SEO MOD after switching to nginx (hopefully within the next 1-2 months).

Regards
Wolfgang
User avatar
IPB_Refugee
PR0
PR0
 
Posts: 82
Joined: Thu Jul 24, 2008 2:18 pm

Re: Rewrite rules for nginx webserver (and phpbb seo)

Postby demon326 » Tue Nov 22, 2011 9:27 pm

Sorry for bumping this topic, but i just want to share the nginx rewrite rules for the following htacces config:

htacces:
Code: Select all

    # Lines That should already be in your .htacess
    <Files "config.php">
    Order Allow,Deny
    Deny from All
    </Files>
    <Files "common.php">
    Order Allow,Deny
    Deny from All
    </Files>

    # You may need to un-comment the following lines
    # Options +FollowSymlinks
    # To make sure that rewritten dir or file (/|.html) will not load dir.php in case it exist
    # Options -MultiViews
    # REMEBER YOU ONLY NEED TO STARD MOD REWRITE ONCE
    RewriteEngine On
    # Uncomment the statement below if you want to make use of
    # HTTP authentication and it does not already work.
    # This could be required if you are for example using PHP via Apache CGI.
    # RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
    # REWRITE BASE
    RewriteBase /forum/
    # HERE IS A GOOD PLACE TO FORCE CANONICAL DOMAIN
    # RewriteCond %{HTTP_HOST} !^domain\.tld$ [NC]
    # RewriteRule ^(.*)$ domain.tld/forum/$1 [QSA,L,R=301]

    # DO NOT GO FURTHER IF THE REQUESTED FILE / DIR DOES EXISTS
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule . - [L]
    #####################################################
    # PHPBB SEO REWRITE RULES ALL MODES
    #####################################################
    # AUTHOR : dcz www.phpbb-seo.com
    # STARTED : 01/2006
    #################################
    # FORUMS PAGES
    ###############
    # FORUM INDEX REWRITERULE WOULD STAND HERE IF USED. "forum" REQUIRES TO BE SET AS FORUM INDEX
    # RewriteRule ^forum\.html$ index.php [QSA,L,NC]
    # FORUM ALL MODES
    RewriteRule ^(forum|[a-z0-9_-]*-f)([0-9]+)/?(page([0-9]+)\.html)?$ viewforum.php?f=$2&start=$4 [QSA,L,NC]
    # TOPIC WITH VIRTUAL FOLDER ALL MODES
    RewriteRule ^(forum|[a-z0-9_-]*-f)([0-9]+)/(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ viewtopic.php?f=$2&t=$4&start=$6 [QSA,L,NC]
    # TOPIC WITHOUT FORUM ID & DELIM ALL MODES
    RewriteRule ^([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ viewtopic.php?forum_uri=$1&t=$3&start=$5 [QSA,L,NC]
    # PHPBB FILES ALL MODES
    RewriteRule ^resources/[a-z0-9_-]+/(thumb/)?([0-9]+)$ download/file.php?id=$2&t=$1 [QSA,L,NC]
    # PROFILES ALL MODES WITH ID
    RewriteRule ^(member|[a-z0-9_-]*-u)([0-9]+)\.html$ memberlist.php?mode=viewprofile&u=$2 [QSA,L,NC]
    # USER MESSAGES ALL MODES WITH ID
    RewriteRule ^(member|[a-z0-9_-]*-u)([0-9]+)-(topics|posts)(-([0-9]+))?\.html$ search.php?author_id=$2&sr=$3&start=$5 [QSA,L,NC]
    # GROUPS ALL MODES
    RewriteRule ^(group|[a-z0-9_-]*-g)([0-9]+)(-([0-9]+))?\.html$ memberlist.php?mode=group&g=$2&start=$4 [QSA,L,NC]
    # POST
    RewriteRule ^post([0-9]+)\.html$ viewtopic.php?p=$1 [QSA,L,NC]
    # ACTIVE TOPICS
    RewriteRule ^active-topics(-([0-9]+))?\.html$ search.php?search_id=active_topics&start=$2&sr=topics [QSA,L,NC]
    # UNANSWERED TOPICS
    RewriteRule ^unanswered(-([0-9]+))?\.html$ search.php?search_id=unanswered&start=$2&sr=topics [QSA,L,NC]
    # NEW POSTS
    RewriteRule ^newposts(-([0-9]+))?\.html$ search.php?search_id=newposts&start=$2&sr=topics [QSA,L,NC]
    # UNREAD POSTS
    RewriteRule ^unreadposts(-([0-9]+))?\.html$ search.php?search_id=unreadposts&start=$2 [QSA,L,NC]
    # THE TEAM
    RewriteRule ^the-team\.html$ memberlist.php?mode=leaders [QSA,L,NC]
    # HERE IS A GOOD PLACE TO ADD OTHER PHPBB RELATED REWRITERULES

    #####################################################
    # GYM Sitemaps & RSS
    # Global channels
    RewriteRule ^rss(/(news)+)?(/(digest)+)?(/(short|long)+)?/?$ gymrss.php?channels&$2&$4&$6 [QSA,L,NC]
    # HTML Global news & maps
    RewriteRule ^(news|maps)/?(page([0-9]+)\.html)?$ map.php?$1&start=$3 [QSA,L,NC]
    # END GYM Sitemaps & RSS
    #####################################################

    # FORUM WITHOUT ID & DELIM ALL MODES
    # THESE THREE LINES MUST BE LOCATED AT THE END OF YOUR HTACCESS TO WORK PROPERLY
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-z0-9_-]+)/?(page([0-9]+)\.html)?$ viewforum.php?forum_uri=$1&start=$3 [QSA,L,NC]
    # FIX RELATIVE PATHS : FILES
    RewriteRule ^.+/(style\.php|ucp\.php|mcp\.php|faq\.php|download/file.php)$ $1 [QSA,L,NC,R=301]
    # FIX RELATIVE PATHS : IMAGES
    RewriteRule ^.+/(styles/.*|images/.*)/$ $1 [QSA,L,NC,R=301]
    # END PHPBB PAGES
    #####################################################

    #####################################################
    # GYM Sitemaps & RSS
    # HTML Module additional modes
    RewriteRule ^(news|maps)/([a-z0-9_-]+)(/([a-z0-9_-]+))?/?(page([0-9]+)\.html)?$ map.php?$2=$4&$1&start=$6 [QSA,L,NC]
    # Main feeds & channels
    RewriteRule ^rss(/(news)+)?(/(digest)+)?(/(short|long)+)?(/([a-z0-9_-]+))?/([a-z0-9_]+)\.xml(\.gz)?$ gymrss.php?$9=$8&$2&$4&$6&gzip=$10 [QSA,L,NC]
    # Module feeds
    RewriteRule ^[a-z0-9_-]*-[a-z]{1,2}([0-9]+)(/(news)+)?(/(digest)+)?(/(short|long)+)?/([a-z0-9_]+)\.xml(\.gz)?$ gymrss.php?$8=$1&$3&$5&$7&gzip=$9 [QSA,L,NC]
    # Module feeds without ids
    RewriteRule ^([a-z0-9_-]+)(/(news)+)?(/(digest)+)?(/(short|long)+)?/([a-z0-9_]+)\.xml(\.gz)?$ gymrss.php?nametoid=$1&$3&$5&$7&modulename=$8&gzip=$9 [QSA,L,NC]
    # Google SitemapIndex
    RewriteRule ^sitemapindex\.xml(\.gz)?$ sitemap.php?gzip=$1 [QSA,L,NC]
    # Module cat sitemaps
    RewriteRule ^[a-z0-9_-]+-([a-z]{1,2})([0-9]+)\.xml(\.gz)?$ sitemap.php?module_sep=$1&module_sub=$2&gzip=$3 [QSA,L,NC]
    # Module sitemaps
    RewriteRule ^([a-z0-9_]+)-([a-z0-9_-]+)\.xml(\.gz)?$ sitemap.php?$1=$2&gzip=$3 [QSA,L,NC]
    # END GYM Sitemaps & RSS
    #####################################################


Nginx:
Please note that i did NOT tested these rewrite rules, but they should work, if they donot work, i cant help, sorry :)
Code: Select all
   rewrite ^/forum\.html$ /index.php last;
   rewrite ^/(forum|[a-z0-9_-]*-f)([0-9]+)/?(page([0-9]+)\.html)?$ /viewforum.php?f=$2&start=$4 last;
   rewrite ^/(forum|[a-z0-9_-]*-f)([0-9]+)/(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?f=$2&t=$4&start=$6 last;
   rewrite /RewriteRule ^/([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$;
   rewrite ^/resources/[a-z0-9_-]+/(thumb/)?([0-9]+)$ /download/file.php?id=$2&t=$1[QSA,L,NC];
   rewrite ^/(member|[a-z0-9_-]*-u)([0-9]+)\.html$ /memberlist.php?mode=viewprofile&u=$2 last;
   rewrite ^/(group|[a-z0-9_-]*-g)([0-9]+)(-([0-9]+))?\.html$ /memberlist.php?mode=group&g=$2&start=$4 last;
   rewrite /RewriteRule ^/post([0-9]+)\.html$;
   rewrite ^/active-topics(-([0-9]+))?\.html$ /search.php?search_id=active_topics&start=$2&sr=topics last;
   rewrite ^/unanswered(-([0-9]+))?\.html$ /search.php?search_id=unanswered&start=$2&sr=topics last;
   rewrite ^/newposts(-([0-9]+))?\.html$search.php?search_id=newposts&start=$2&sr=topics /[QSA,L,NC];
   rewrite ^/unreadposts(-([0-9]+))?\.html$ /search.php?search_id=unreadposts&start=$2 last;
   rewrite ^/the-team\.html$ /memberlist.php?mode=leaders last;
   rewrite ^/rss(/(news)+)?(/(digest)+)?(/(short|long)+)?/?$ /gymrss.php?channels&$2&$4&$6 last;
   rewrite ^/(news|maps)/?(page([0-9]+)\.html)?$ /map.php?$1&start=$3 last;
   rewrite ^/([a-z0-9_-]+)/?(page([0-9]+)\.html)?$ /viewforum.php?forum_uri=$1&start=$3 last;
   rewrite ^/.+/(style\.php|ucp\.php|mcp\.php|faq\.php|download/file.php)$ /$1 permanent;
   break;
   rewrite ^/.+/(styles/.*|images/.*)/$ /$1 permanent;
   break;
   rewrite ^/(news|maps)/([a-z0-9_-]+)(/([a-z0-9_-]+))?/?(page([0-9]+)\.html)?$ /map.php?$2=$4&$1&start=$6 last;
   rewrite ^/rss(/(news)+)?(/(digest)+)?(/(short|long)+)?(/([a-z0-9_-]+))?/([a-z0-9_]+)\.xml(\.gz)?$ /gymrss.php?$9=$8&$2&$4&$6&gzip=$10 last;
   rewrite ^/[a-z0-9_-]*-[a-z]{1,2}([0-9]+)(/(news)+)?(/(digest)+)?(/(short|long)+)?/([a-z0-9_]+)\.xml(\.gz)?$ /gymrss.php?$8=$1&$3&$5&$7&gzip=$9 last;
   rewrite ^/([a-z0-9_-]+)(/(news)+)?(/(digest)+)?(/(short|long)+)?/([a-z0-9_]+)\.xml(\.gz)?$ /gymrss.php?nametoid=$1&$3&$5&$7&modulename=$8&gzip=$9 last;
   rewrite ^/sitemapindex\.xml(\.gz)?$ /sitemap.php?gzip=$1 last;
   rewrite ^/[a-z0-9_-]+-([a-z]{1,2})([0-9]+)\.xml(\.gz)?$ /sitemap.php?module_sep=$1&module_sub=$2&gzip=$3 last;
   rewrite ^/([a-z0-9_]+)-([a-z0-9_-]+)\.xml(\.gz)?$ /sitemap.php?$1=$2&gzip=$3 last;
demon326
 
Posts: 19
Joined: Wed Jul 23, 2008 8:27 pm

Re: Rewrite rules for nginx webserver (and phpbb seo)

Postby bweston1a » Sun Feb 16, 2014 6:22 pm

dcz wrote:Interesting, so apart from slashes and flags, rewriterules are basically the same as with Apache. Our mod rewrite's .htaccess have changed a bit since the last version, since all modes have been unified, but the same principle should still work.

We should think one day about making our .htaccess generator to generate more than .htaccess for other servers ;)


I don't mean to bump such an old thread. But I was wondering if there has been any progress toward building in support for nginx rewrite rules.

I'll post my experience in another thread. But in a nutshell, I've had problems with enabling the virtual folder.

I'd be happy to lend whatever help I could provide to the process. I'm currently testing all this on an Amazon EC2 instance. But I plan to migrate my production site to nginx in the future. I'd like to keep the phpbb-seo mod. So anything I can do to help move this along, I'd be happy to do.
bweston1a
 
Posts: 8
Joined: Thu May 12, 2011 11:33 pm

Re: Rewrite rules for nginx webserver (and phpbb seo)

Postby NorteX » Wed Mar 19, 2014 1:58 pm

Hello guys,

I am completely new to all this but I also wonder if the phpBB SEO is still in development and fits for the latest phpBB3. I also have nginx and would love to get some support for the rewrite rules <3

THanks in advance!
NorteX
 
Posts: 1
Joined: Wed Mar 19, 2014 1:56 pm


Return to phpBB mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 9 guests