Nginx rewrite rules

Discussions about the phpBB3 Forum. How to get the best from this powerful script.
Note that there is no official support for phpBB3 here, a place to share more than to ask for.

Moderator: Moderators

Nginx rewrite rules

Postby Demontager » Fri Mar 08, 2013 9:41 am

I'm using Nginx+phpFPM and .htaccess for phpBB should be rewritten for nginx of course. Used this tool for automatic conversion - http://winginx.ru/htaccess
put few rules, but rewrite doesn't work.
Original .htaccess
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 /
# HERE IS A GOOD PLACE TO FORCE CANONICAL DOMAIN
# RewriteCond %{HTTP_HOST} !^localhost/forum$ [NC]
# RewriteRule ^(.*)$ http://localhost/forum/$1 [QSA,L,R=301]

# DO NOT GO FURTHER IF THE REQUESTED FILE / DIR DOES EXISTS
RewriteCond %{REQUEST_FILENAME} -f
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]+)(-([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 THROUGH USERNAME
RewriteRule ^member/([^/]+)/?$ /memberlist.php?mode=viewprofile&un=$1 [QSA,L,NC]
# USER MESSAGES THROUGH USERNAME
RewriteRule ^member/([^/]+)/(topics|posts)/?(page([0-9]+)\.html)?$ /search.php?author=$1&sr=$2&start=$4 [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

# FORUM WITHOUT ID & DELIM ALL MODES
# THESE FOUR LINES MUST BE LOCATED AT THE END OF YOUR HTACCESS TO WORK PROPERLY
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z0-9_-]+)(-([0-9]+))\.html$ /viewforum.php?forum_uri=$1&start=$3 [QSA,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z0-9_-]+)\.html$ /viewforum.php?forum_uri=$1 [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


And Rewrite rules in nginx:
Code: Select all
server {
listen 80;
server_name www.domain.com;
rewrite ^ http://domain.com$request_uri?;
error_log /var/log/www/domain.com/nerror.log;
}
server {
listen 80;
server_name domain.com;
server_name_in_redirect off;
root /usr/local/www/domain.com;
index index.php index.html index.htm;
location ~* ^.+\.(ico|js|gif|jpg|jpeg|png|bmp)$ {
expires 30d;
}
location /post { rewrite ^/post([0-9]+)\.html$ /viewtopic.php?p=$1 break; }

location / {
try_files $uri $uri/ /index.php;
rewrite ^/(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$ /viewforum.php?f=$2&start=$4 break;
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 break;
}
location ~ /(config\.php|common\.php|cache|files|images/avatars/upload|includes|store) {
deny all;
return 403;
}

location ~ \.php$ {
# fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;


include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;

}
location ~ /\.ht {
deny all;
}
}

Demontager
 
Posts: 5
Joined: Fri Mar 08, 2013 9:31 am

Advertisement

Re: Nginx rewrite rules

Postby whocarez » Fri Mar 08, 2013 4:17 pm

Here are my rules. Maybe it helps ....
Note, that I use unicode characters in my links. See this post:
Re: phpbb seo why not support unicode?

Code: Select all
if (!-e $request_filename) {

# FORUM INDEX REWRITERULE WOULD STAND HERE IF USED. "forum" REQUIRES TO BE SET AS FORUM INDEX
# rewrite ^/forum\.html$ /index.php last;
# FORUM ALL MODES
rewrite ^/(forum|.*-f)([0-9]+)(-([0-9]+))?\.html$ /viewforum.php?f=$2&start=$4 last;
# TOPIC WITH VIRTUAL FOLDER ALL MODES
rewrite ^/(forum|.*-f)([0-9]+)/(thema|topic|[a-z\x7f-\xff0-9-_]*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?f=$2&t=$4&start=$6 last;
# GLOBAL ANNOUNCES WITH VIRTUAL FOLDER ALL MODES
rewrite ^/(bekanntmachungen|announces)/(thema|topic|.*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?t=$3&start=$5 last;
# TOPIC WITHOUT FORUM ID & DELIM ALL MODES
rewrite ^/(.*)/?(thema|topic|.*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?forum_uri=$1&t=$3&start=$5 last;
# PHPBB FILES ALL MODES
rewrite ^/resources/.+/(thumb/)?([0-9]+)$ /download/file.php?id=$2&t=$1 last;
# PROFILES ALL MODES WITH ID
rewrite ^/(mitglied|member|.*-u)([0-9]+)\.html$ /memberlist.php?mode=viewprofile&u=$2 last;
# USER MESSAGES ALL MODES WITH ID
rewrite ^/(mitglied|member|.*-u)([0-9]+)-(topics|posts)(-([0-9]+))?\.html$ /search.php?author_id=$2&sr=$3&start=$5 last;
# GROUPS ALL MODES
rewrite ^/(gruppe|group|.*-g)([0-9]+)(-([0-9]+))?\.html$ /memberlist.php?mode=group&g=$2&start=$4 last;
# POST
rewrite ^/(beitrag|post)([0-9]+)\.html$ /viewtopic.php?p=$2 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;
# UNREAD POSTS
rewrite ^/unreadposts(-([0-9]+))?\.html$ /search.php?search_id=unreadposts&start=$2 last;
# THE TEAM
rewrite ^/(the|das)-team\.html$ /memberlist.php?mode=leaders last;

    #####################################################
    # GYM Sitemaps & RSS
    # Global channels
    # NOTE : THE FOLLOWING REWRITERULE IS LEFT COMMENTED BECAUSE IT CANNOT
    # BE IMPLEMENTED IN THIS .HTACCESS, BUT RATHER IN AN ABOVE ONE
    # WITH PROPER SLASHES AND PATHS
     rewrite ^/rss(/(news)+)?(/(digest)+)?(/(short|long)+)?/?$ /gymrss.php?channels&$2&$4&$6 last;
    # HTML Global news & maps
    # NOTE : THE FOLLOWING REWRITERULE IS LEFT COMMENTED BECAUSE IT CANNOT
    # BE IMPLEMENTED IN THIS .HTACCESS, BUT RATHER IN AN ABOVE ONE
    # WITH PROPER SLASHES AND PATHS
     rewrite ^/(news|maps)/?(page([0-9]+)\.html)?$ /map.php?$1&start=$3 last;
    # END GYM Sitemaps & RSS
    #####################################################

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

    #####################################################
    # GYM Sitemaps & RSS
    # HTML Module additional modes
    # NOTE : THE FOLLOWING REWRITERULE IS LEFT COMMENTED BECAUSE IT CANNOT
    # BE IMPLEMENTED IN THIS .HTACCESS, BUT RATHER IN AN ABOVE ONE
    # WITH PROPER SLASHES AND PATHS
     rewrite ^/(news|maps)/([a-z\x7f-\xff0-9_-]+)(/([a-z\x7f-\xff0-9_-]+))?/?(page([0-9]+)\.html)?$ /map.php?$2=$4&$1&start=$6 last;
    # Main feeds & channels
    # NOTE : THE FOLLOWING REWRITERULE IS LEFT COMMENTED BECAUSE IT CANNOT
    # BE IMPLEMENTED IN THIS .HTACCESS, BUT RATHER IN AN ABOVE ONE
    # WITH PROPER SLASHES AND PATHS
     rewrite ^/rss(/(news)+)?(/(digest)+)?(/(short|long)+)?(/([a-z\x7f-\xff0-9_-]+))?/([a-z\x7f-\xff0-9_]+)\.xml(\.gz)?$ /gymrss.php?$9=$8&$2&$4&$6&gzip=$10 last;
    # Module feeds
    # NOTE : THE FOLLOWING REWRITERULE IS LEFT COMMENTED BECAUSE IT CANNOT
    # BE IMPLEMENTED IN THIS .HTACCESS, BUT RATHER IN AN ABOVE ONE
    # WITH PROPER SLASHES AND PATHS
     rewrite ^/[a-z\x7f-\xff0-9_-]*-[a-z\x7f-\xff]([0-9]+)(/(news)+)?(/(digest)+)?(/(short|long)+)?/([a-z\x7f-\xff0-9_]+)\.xml(\.gz)?$ /gymrss.php?$8=$1&$3&$5&$7&gzip=$9 last;
    # Module feeds without ids
    # NOTE : THE FOLLOWING REWRITERULE IS LEFT COMMENTED BECAUSE IT CANNOT
    # BE IMPLEMENTED IN THIS .HTACCESS, BUT RATHER IN AN ABOVE ONE
    # WITH PROPER SLASHES AND PATHS
     rewrite ^/([a-z\x7f-\xff0-9_-]+)(/(news)+)?(/(digest)+)?(/(short|long)+)?/([a-z\x7f-\xff0-9_]+)\.xml(\.gz)?$ /gymrss.php?nametoid=$1&$3&$5&$7&modulename=$8&gzip=$9 last;
    # Google SitemapIndex
    # NOTE : THE FOLLOWING REWRITERULE IS LEFT COMMENTED BECAUSE IT CANNOT
    # BE IMPLEMENTED IN THIS .HTACCESS, BUT RATHER IN AN ABOVE ONE
    # WITH PROPER SLASHES AND PATHS
     rewrite ^/sitemapindex\.xml(\.gz)?$ /sitemap.php?gzip=$1 last;
    # Module cat sitemaps
    # NOTE : THE FOLLOWING REWRITERULE IS LEFT COMMENTED BECAUSE IT CANNOT
    # BE IMPLEMENTED IN THIS .HTACCESS, BUT RATHER IN AN ABOVE ONE
    # WITH PROPER SLASHES AND PATHS
     rewrite ^/[a-z\x7f-\xff0-9_-]+-([a-z\x7f-\xff])([0-9]+)\.xml(\.gz)?$ /sitemap.php?module_sep=$1&module_sub=$2&gzip=$3 last;
    # Module sitemaps
    # NOTE : THE FOLLOWING REWRITERULE IS LEFT COMMENTED BECAUSE IT CANNOT
    # BE IMPLEMENTED IN THIS .HTACCESS, BUT RATHER IN AN ABOVE ONE
    # WITH PROPER SLASHES AND PATHS
     rewrite ^/([a-z\x7f-\xff0-9_]+)-([a-z\x7f-\xff0-9_-]+)\.xml(\.gz)?$ /sitemap.php?$1=$2&gzip=$3 last;
    # END GYM Sitemaps & RSS
    #####################################################

}

whocarez
 
Posts: 16
Joined: Mon Mar 29, 2010 6:36 pm

Re: Nginx rewrite rules

Postby Demontager » Fri Mar 08, 2013 6:07 pm

whocarez, thanks for reply, tried even full your config no changes. I put at least most important rewrites, no effect. :(
Code: Select all
server {
        listen 80;
        server_name www.domain.com;
        rewrite ^ http://domain.com$request_uri?;
error_log /var/log/www/domain.com/nerror.log;
}
server {
        listen 80;
        server_name domain.com;
        server_name_in_redirect off;
        root /usr/local/www/domain.com;
        index index.php index.html index.htm;
        location ~* ^.+\.(ico|js|gif|jpg|jpeg|png|bmp)$ {
          expires 30d;
        }
                 
        location / {
            try_files $uri $uri/ /index.php;
            rewrite ^/(forum|[a-z0-9_-]*-f)([0-9]+)(-([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 ^/post([0-9]+)\.html$ /viewtopic.php?p=$1 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 ^/([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?forum_uri=$1&t=$3&start=$5 last;
            rewrite ^/resources/[a-z0-9_-]+/(thumb/)?([0-9]+)$ /download/file.php?id=$2&t=$1 last;
            rewrite ^/post([0-9]+)\.html$ /viewtopic.php?p=$1 last;
            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 last;
            rewrite ^/unreadposts(-([0-9]+))?\.html$ /search.php?search_id=unreadposts&start=$2 last;
           
           
           
        }
           location ~ /(config\.php|common\.php|cache|files|images/avatars/upload|includes|store) {
        deny all;
        return 403;
    }
   
        location ~ \.php$ {
                    # fastcgi_split_path_info ^(.+\.php)(.*)$;
                    fastcgi_pass   unix:/tmp/php-fpm.sock;
                fastcgi_param  DOCUMENT_ROOT    $document_root;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_script_name;


  include fastcgi_params;
  fastcgi_param  QUERY_STRING     $query_string;
  fastcgi_param  REQUEST_METHOD   $request_method;
  fastcgi_param  CONTENT_TYPE     $content_type;
  fastcgi_param  CONTENT_LENGTH   $content_length;
  fastcgi_intercept_errors        on;
  fastcgi_ignore_client_abort     off;
  fastcgi_connect_timeout 60;
  fastcgi_send_timeout 180;
  fastcgi_read_timeout 180;
  fastcgi_buffer_size 128k;
  fastcgi_buffers 4 256k;
  fastcgi_busy_buffers_size 256k;
  fastcgi_temp_file_write_size 256k;

        }
        location ~ /\.ht {
            deny all;
        }
}




Demontager
 
Posts: 5
Joined: Fri Mar 08, 2013 9:31 am

Re: Nginx rewrite rules

Postby whocarez » Sun Mar 10, 2013 12:27 am

ok, can you please be more specific, what is exactly not working? Not working means 404, right?
For example:

Is
Code: Select all
domain.com/post1234.html
working?

Which forum-structure do you have? Are Forumnumbers deleted? Or do you have forumnumbers, inside your forumnames?
domain.com/forumname-fxy.html

What is with topics? Are they with numbers or without?
In my opinion it is easier to manage forumnames like
Code: Select all
domain.com/forumname-f123
than
Code: Select all
domain.com/forumname
and the same for topics .... and so on.

For testing purposes I relay on
Code: Select all
curl -I url
whocarez
 
Posts: 16
Joined: Mon Mar 29, 2010 6:36 pm

Re: Nginx rewrite rules

Postby Demontager » Sun Mar 10, 2013 1:07 pm

I meant rewrites not working in nginx. The real forum where I testing this - tangoresults.com . For example i took working URL
Code: Select all
http://tangoresults.com/viewtopic.php?f=6&t=3

which after enabled phpBBSEO rewrites looks like
Code: Select all
http://tangoresults.com/topic3.html


PhpBB generated a .htaccess code which i transformed to such config:
Code: Select all
server {
        listen 80;
        server_name www.tangoresults.com;
        rewrite ^ http://tangoresults.com$request_uri?;

}
server {
        listen 80;
        server_name tangoresults.com;
        server_name_in_redirect off;
        root /usr/local/www/tangoresults.com;
        index index.php index.html index.htm;
        rewrite_log     on;
        error_log /var/log/www/tangoresults.com/nerror.log debug;
        location ~* ^.+\.(ico|js|gif|jpg|jpeg|png|bmp)$ {
          expires 30d;
        }
                 
location / {
    try_files $uri @rewrite;
}
   
        location @rewrite {
        rewrite ^/$ /index.php last;
        rewrite ^(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$ 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 ^([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?forum_uri=$1&t=$3&start=$5 last;
        rewrite ^resources/[a-z0-9_-]+/(thumb/)?([0-9]+)$ /download/file.php?id=$2&t=$1 last;
        rewrite ^member/([^/]+)/?$ /memberlist.php?mode=viewprofile&un=$1 last;
        rewrite ^member/([^/]+)/(topics|posts)/?(page([0-9]+)\.html)?$ /search.php?author=$1&sr=$2&start=$4 last;
        rewrite ^(group|[a-z0-9_-]*-g)([0-9]+)(-([0-9]+))?\.html$ /memberlist.php?mode=group&g=$2&start=$4 last;
        rewrite ^post([0-9]+)\.html$ /viewtopic.php?p=$1 last;
        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 last;
        rewrite ^unreadposts(-([0-9]+))?\.html$ /search.php?search_id=unreadposts&start=$2 last;
        rewrite ^the-team\.html$ /memberlist.php?mode=leaders last;
    }
         
        location ~ \.php$ {
                    # fastcgi_split_path_info ^(.+\.php)(.*)$;
                    fastcgi_pass   unix:/tmp/php-fpm.sock;
                fastcgi_param  DOCUMENT_ROOT    $document_root;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_script_name;


  include fastcgi_params;
  fastcgi_param  QUERY_STRING     $query_string;
  fastcgi_param  REQUEST_METHOD   $request_method;
  fastcgi_param  CONTENT_TYPE     $content_type;
  fastcgi_param  CONTENT_LENGTH   $content_length;
  fastcgi_intercept_errors        on;
  fastcgi_ignore_client_abort     off;
  fastcgi_connect_timeout 60;
  fastcgi_send_timeout 180;
  fastcgi_read_timeout 180;
  fastcgi_buffer_size 128k;
  fastcgi_buffers 4 256k;
  fastcgi_busy_buffers_size 256k;
  fastcgi_temp_file_write_size 256k;

        }
        location ~ /\.ht {
            deny all;
        }
}




Demontager
 
Posts: 5
Joined: Fri Mar 08, 2013 9:31 am

Re: Nginx rewrite rules

Postby Demontager » Sun Mar 10, 2013 1:38 pm

I fetched rewrite info from log, seems rewrites working fine for topics, but not for forums

##################GETTING topic4.html, topic2.html#########################################################
Code: Select all
2013/03/10 14:29:16 [notice] 5385#0: *85 "^/$" does not match "/topic4.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /topic4.html HTTP/1.1", host: "tangoresults.com"
2013/03/10 14:29:16 [notice] 5385#0: *85 "^(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$" does not match "/topic4.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /topic4.html HTTP/1.1", host: "tangoresults.com"
2013/03/10 14:29:16 [notice] 5385#0: *85 "^(forum|[a-z0-9_-]*-f)([0-9]+)/(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$" does not match "/topic4.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /topic4.html HTTP/1.1", host: "tangoresults.com"
2013/03/10 14:29:16 [notice] 5385#0: *85 "^([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$" matches "/topic4.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /topic4.html HTTP/1.1", host: "tangoresults.com"
2013/03/10 14:29:16 [notice] 5385#0: *85 rewritten data: "/viewtopic.php", args: "forum_uri=&t=4&start=", client: 94.153.55.89, server: tangoresults.com, request: "GET /topic4.html HTTP/1.1", host: "tangoresults.com"
2013/03/10 14:29:26 [notice] 5385#0: *89 "^/$" does not match "/topic2.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /topic2.html HTTP/1.1", host: "tangoresults.com"
2013/03/10 14:29:26 [notice] 5385#0: *89 "^(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$" does not match "/topic2.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /topic2.html HTTP/1.1", host: "tangoresults.com"
2013/03/10 14:29:26 [notice] 5385#0: *89 "^(forum|[a-z0-9_-]*-f)([0-9]+)/(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$" does not match "/topic2.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /topic2.html HTTP/1.1", host: "tangoresults.com"
2013/03/10 14:29:26 [notice] 5385#0: *89 "^([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$" matches "/topic2.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /topic2.html HTTP/1.1", host: "tangoresults.com"
2013/03/10 14:29:26 [notice] 5385#0: *89 rewritten data: "/viewtopic.php", args: "forum_uri=&t=2&start=", client: 94.153.55.89, server: tangoresults.com, request: "GET /topic2.html HTTP/1.1", host: "tangoresults.com"


##################GETING forum9.html#########################################################################
Code: Select all
2013/03/10 14:30:41 [notice] 5385#0: *99 "^/$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^(forum|[a-z0-9_-]*-f)([0-9]+)/(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^resources/[a-z0-9_-]+/(thumb/)?([0-9]+)$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^member/([^/]+)/?$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^member/([^/]+)/(topics|posts)/?(page([0-9]+)\.html)?$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^(group|[a-z0-9_-]*-g)([0-9]+)(-([0-9]+))?\.html$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^post([0-9]+)\.html$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^active-topics(-([0-9]+))?\.html$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^unanswered(-([0-9]+))?\.html$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^newposts(-([0-9]+))?\.html$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^unreadposts(-([0-9]+))?\.html$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [notice] 5385#0: *99 "^the-team\.html$" does not match "/forum9.html", client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"
2013/03/10 14:30:41 [error] 5385#0: *99 open() "/usr/local/www/tangoresults.com/forum9.html" failed (2: No such file or directory), client: 94.153.55.89, server: tangoresults.com, request: "GET /forum9.html HTTP/1.1", host: "tangoresults.com", referrer: "http://tangoresults.com/topic2.html"

Demontager
 
Posts: 5
Joined: Fri Mar 08, 2013 9:31 am

Re: Nginx rewrite rules

Postby ludo345 » Thu Mar 14, 2013 4:50 pm

Hello,

Do you have see that ?

Difficulties with phpBB SEO & nginx

++
ludo345
 
Posts: 8
Joined: Sun Feb 03, 2008 10:31 am

Re: Nginx rewrite rules

Postby whocarez » Thu Mar 14, 2013 7:05 pm

Demontager wrote:I fetched rewrite info from log, seems rewrites working fine for topics, but not for forums

try to add a slash to your rewrite rules

Code: Select all
2013/03/10 14:30:41 [notice] 5385#0: *99 "^(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$" does not match "/forum9.html"

I suppose that it would match, if you have
Code: Select all
rewrite ^/(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$ last;

instead of the variant without the first slash ...

good luck
whocarez
 
Posts: 16
Joined: Mon Mar 29, 2010 6:36 pm

Re: Nginx rewrite rules

Postby Demontager » Fri Mar 15, 2013 2:45 pm

After few experiments found forums match working with rewrite ^/(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$ /viewforum.php?f=$2&start=$4 last;
But, got another problem with sessions. For example, if i log in with some user, after succesfull login it log outs automatically. I guess this happen because sid strings changes, e.g before ucp.php?mode=login&sid=f4e283c4e1fb7b444ac1316b5bd47c6b after ucp.php?mode=login&sid=5caa0d17567b81bf7008382e3071776c
Rewrite config now as follows:
Code: Select all
location / {
    try_files $uri @rewrite;
}
   
        location @rewrite {
        rewrite ^/$ /index.php last;
        rewrite ^/(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$ /viewforum.php?f=$2&start=$4 last;
        rewrite ^/(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$ 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 ^([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?forum_uri=$1&t=$3&start=$5 last;
        rewrite ^resources/[a-z0-9_-]+/(thumb/)?([0-9]+)$ /download/file.php?id=$2&t=$1 last;
        rewrite ^member/([^/]+)/?$ /memberlist.php?mode=viewprofile&un=$1 last;
        rewrite ^member/([^/]+)/(topics|posts)/?(page([0-9]+)\.html)?$ /search.php?author=$1&sr=$2&start=$4 last;
        rewrite ^(group|[a-z0-9_-]*-g)([0-9]+)(-([0-9]+))?\.html$ /memberlist.php?mode=group&g=$2&start=$4 last;
        rewrite ^post([0-9]+)\.html$ /viewtopic.php?p=$1 last;
        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 last;
        rewrite ^unreadposts(-([0-9]+))?\.html$ /search.php?search_id=unreadposts&start=$2 last;
        rewrite ^the-team\.html$ /memberlist.php?mode=leaders last;
    }
Demontager
 
Posts: 5
Joined: Fri Mar 08, 2013 9:31 am

Re: Nginx rewrite rules

Postby bweston1a » Sun Feb 16, 2014 9:05 pm

deleted post. (posted to wrong thread)
bweston1a
 
Posts: 8
Joined: Thu May 12, 2011 11:33 pm


Return to phpBB Forum

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: Google Adsense [Bot] and 88 guests