giO89R
By:
giO89R

.htaccess to Nginx PHPBB Seo Rewrite Mode

October 31, 2014 5.4k views

Hello!
I just trasferred everything to DigitalOcean a week ago, 2 wordpress blogs and a phpbb forum and switched from Apache to Nginx.
I had no problem to create the proper Server Block to rewrite urls for wordpress, but I'm having some problem with the PHPBB forum.
I tried to convert the .htaccess to nginx, but no success. I get 404 Page Not Found.

Here's the Server Block: http://pastebin.com/1wHL3LcA (without the converted .htaccess)
Here's the .htaccess I used on Apache: http://pastebin.com/8cQLxVsA

Any suggestion?
Thanks.

2 Answers

As far as I know, Apache has mods that Nginx doesn't. I assume you'd need mod_rewrite, so you'd probably have to write your own or find an Nginx one that's not in a business environment so someone would share it. Apache is so much simpler in this context, I'd recommend swapping back.

  • Thanks for the answer.
    I know Apache is simpler than Nginx about these things, (currently I'm having issue only for phpbb seo rewrite mode) but I switched to it because has better performance, specially using wordpress, or serving static files such as images, js and css etc. (I had some slowdown using Apache, meanwhile on Nginx everything is faster)
    I'll see what I can do.

  • nginx does support rewrites, but you probably won't need it. Check out Nginx configuration for phpBB - Nginx Library.

  • This can be helpful for someone in the future.
    I solved the problem just adding this to my nginx server block:
    Note: This works only if the forum is in a sub-folder, like domain.com/forum/
    Pastebin here: PHPBB Seo for Nginx

    # PHPBB Seo Rewrite Mode for Nginx
    
        # Serve Static Files Directly
            location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml|txt)$ {
                access_log        off;
                expires           30d;
            }
    
            location /forum/ {
            rewrite ^/forum/(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$ /forum/viewforum.php?f=$2&start=$4 last;
            rewrite ^/forum/(forum|[a-z0-9_-]*-f)([0-9]+)/(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /forum/viewtopic.php?f=$2&t=$4&start=$6 last;
            rewrite ^/forum/([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /forum/viewtopic.php?forum_uri=$1&t=$3&start=$5 last;
            rewrite ^/forum/(member|[a-z0-9_-]*-u)([0-9]+)\.html$ /forum/memberlist.php?mode=viewprofile&u=$2 last;
            rewrite ^/forum/(member|[a-z0-9_-]*-u)([0-9]+)-(topics|posts)(-([0-9]+))?\.html$ /forum/search.php?author_id=$2&sr=$3&start=$5 last;
            rewrite ^/forum/(group|[a-z0-9_-]*-g)([0-9]+)(-([0-9]+))?\.html$ /forum/memberlist.php?mode=group&g=$2&start=$4 last;
            rewrite ^/forum/([a-z0-9_-]+)(-([0-9]+))\.html$ /forum/viewforum.php?forum_uri=$1&start=$3 last;
            rewrite ^/forum/([a-z0-9_-]+)\.html$ /forum/viewforum.php?forum_uri=$1 last;
            rewrite ^/forum/.+/(style\.php|ucp\.php|mcp\.php|faq\.php|download/file.php)$ /forum/$1 redirect;
            rewrite ^/forum/.+/(styles/.*|images/.*)/$ /forum/$1 redirect;
            }
            location /forum/resources {
            rewrite ^/forum/resources/[a-z0-9_-]+/(thumb/)?([0-9]+)$ /forum/download/file.php?id=$2&t=$1 last;
            }
            location /forum/post {
            rewrite ^/forum/post([0-9]+)\.html$ /forum/viewtopic.php?p=$1 last;
            }
            location /forum/active {
            rewrite ^/forum/active-topics(-([0-9]+))?\.html$ /forum/search.php?search_id=active_topics&start=$2&sr=topics last;
            }
            location /forum/unanswered {
            rewrite ^/forum/unanswered(-([0-9]+))?\.html$ /forum/search.php?search_id=unanswered&start=$2&sr=topics last;
            }
            location /forum/newposts {
            rewrite ^/forum/newposts(-([0-9]+))?\.html$ /forum/search.php?search_id=newposts&start=$2&sr=topics last;
            }
            location /forum/unreadposts {
            rewrite ^/forum/unreadposts(-([0-9]+))?\.html$ /forum/search.php?search_id=unreadposts&start=$2 last;
            }
            location /forum/the {
            rewrite ^/forum/the-team\.html$ /forum/memberlist.php?mode=leaders last;
            }
            location /forum/config.php {
            deny all;
            }
            location /forum/common.php {
            deny all;
            }
    

this is the main problem in my website i want to clean the url i used .htaccess file to edit it my url become
http://www.alsaleh-group.com/3/furniture-transfer-dammam-company
/post.php?id=3&url=furniture-transfer-dammam-company
the code inside htaccess is

RewriteEngine On
RewriteRule ^([^/])/([^/]).html$ /post.php?id=$1&url=$2 [L]

i hope this help it work with me perfect and i put the url in my reply to check it
thank you

Have another answer? Share your knowledge.