phpbb-seo, nginx and virtual folder problems

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

Moderator: Moderators

phpbb-seo, nginx and virtual folder problems

Postby bweston1a » Sun Feb 16, 2014 7:06 pm

Let me start out by saying I love this mod. It's been a big boost to my site.

Now for my problem. I'm planning to move off of apache and on to the nginx web server.

Without getting into all the details, it's a faster, lighter-weight web server (in my opinion). I've been in the process of rewriting the htaccess files from phpbb-seo (premod, advanced setting).

I've worked through most of the bugs. All but one, in fact.

Whenever I enable the Virtual Folder option, my SUB forums go completely 404. I can hit the main forum page. But any sub forum stops working with 404.

I have all the other premod settings enabled, except the "Activate sql rewriting." It all works fine, up until I enable the Virtual Folder option.

I'm doing this work on an Amazon EC2 instance. So I can make tweaks and afford some down time while making these changes. I'd appreciate any help anyone could provide.

It would be great if there was an option to automatically generate nginx rewrite rules.

As I noted in another thread earlier today, I'd be happy to help with anything I could do to help the cause of getting a rewrite feature built in for nginx (inside the phpbb-seo mod).

Anyway, below are the particulars of my environment

I'm running a clean version of phpbb-seo premod 3.0.12.

here is the link to my EC2 instance:

Here is the main forum page (rewritten from -http://54.84.155.107/forums2/)

My phpbb-seo premod is installed in a subfolder (/forums2).

http://54.84.155.107/forum.html

If I enable the virtual folder and go to a subforum, I get a 404 error:
(please note the hyphen preceding the links below, I need to add it so i could post these additional links (since i don't have more than 10 posts on this forum).

-http://54.84.155.107/your-first-forum/

If I disable the virtual folder , it works:

-http://54.84.155.107/your-first-forum.html

Here is my nginx rewrite conf

Code: Select all
server {
  #SET SERVER VARIABLE HERE SO I DON'T NEED TO CHANGE IT IN A BUNCH OF PLACES BELOW
  set $my_site "54.84.155.107";

  listen 80;
  server_name $my_site;

  # HERE IS A GOOD PLACE TO FORCE CANONICAL DOMAIN
  if ( $host != '$my_site' ) {
   rewrite ^/(.*)$ http://$my_site/$1 permanent;
  }
  access_log /var/log/nginx/my_site.access_log;
  error_log /var/log/nginx/my_site.error_log;

  #root /var/www/www.domain.tld;
  root /usr/share/nginx/www/my-nginx-rewrite-rules/current;
  index index.php index.htm index.html;

  # serve static files directly
  location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml|txt)$ {
    access_log off;
    expires 30d;
  }

  location ~ /(config\.php|common\.php|cache|files|images/avatars/upload|includes|store) {
    deny all;
    return 403;
  }

  # ADDS SUPPORT FOR PHPBB TO NGINX
  location ~ .php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/www/my-nginx-rewrite-rules/current$fastcgi_script_name;
    include fastcgi_params;
    try_files $uri =404;
  }

  location /images {
    root /usr/share;
    autoindex on;
  }

  location = /50x.html {
    #root /usr/share/nginx/www;
    root /usr/share/nginx/www/my-nginx-rewrite-rules/current;
  }


#begin SEO secton
# Need to translate the deny
# THIS DIRECTIVE DOES NOT WORK. CAUSES A 404 ERROR
  # DO NOT GO FURTHER does  THE REQUESTED FILE / folder DOES EXISTS
#  if (!-e $request_filename) {
#    rewrite . - last;
#  }
  #####################################################
  # PHPBB SEO REWRITE RULES ALL MODES
  #####################################################

  location / {

  # FORUMS PAGES
  ###############
  # FORUM INDEX
  rewrite ^/forum\.html$ /forums2/index.php last;

  # FORUM ALL MODES
  rewrite ^/(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$ /forums2/viewforum.php?f=$2&start=$4 last;

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

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

  # PHPBB FILES ALL MODES
  rewrite ^/resources/[a-z0-9_-]+/(thumb/)?([0-9]+)$ /forums2/download/file.php?id=$2&t=$1 last;

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

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

  # GROUPS ALL MODES
  rewrite ^/(group|[a-z0-9_-]*-g)([0-9]+)(-([0-9]+))?\.html$ /forums2/memberlist.php?mode=group&g=$2&start=$4 last;

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

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

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

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

  # UNREAD POSTS
  rewrite ^/unreadposts(-([0-9]+))?\.html$ /forums2/search.php?search_id=unreadposts&start=$2 last;

  # THE TEAM
  rewrite ^/the-team\.html$ /forums2/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)+)?/?$ /forums2/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)?$ /forums2/map.php?$1&start=$3 last;
  # END GYM Sitemaps & RSS
  #####################################################



  # 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

  if (!-f $request_filename) {
    rewrite ^/([a-z0-9_-]+)(-([0-9]+))\.html$ /forums2/viewforum.php?forum_uri=$1&start=$3 last;
  }

  if (!-f $request_filename) {
    rewrite ^/([a-z0-9_-]+)\.html$ /forums2/viewforum.php?forum_uri=$1 last;
  }

  # FIX RELATIVE PATHS : FILES
  rewrite ^/forums2/.+/(style\.php|ucp\.php|mcp\.php|faq\.php|download/file.php)$ /forums2/$1 last;

  # FIX RELATIVE PATHS : IMAGES
  rewrite ^/forums2/.+/(styles/.*|images/.*)/$ /forums2/$1 last;

  # END PHPBB PAGES
  #####################################################

  }
}
Last edited by bweston1a on Mon Feb 17, 2014 5:12 am, edited 1 time in total.
bweston1a
 
Posts: 8
Joined: Thu May 12, 2011 11:33 pm

Advertisement

Re: phpbb-seo, nginx and virtual folder problems

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

Ok. I think I found the issue.

Basically, to handle doing a multiview (where the subforum name changes from forum_name.html to just forum_name, I needed to add the following bit of code below the last location declaration (but before the ending server brace (})

Code: Select all
location ~ ^(.+)/$ {
  try_files $uri $1.html?$args;
}


Here is the full nginx conf file with the change:

Code: Select all
server {
  #SET SERVER VARIABLE HERE SO I DON'T NEED TO CHANGE IT IN A BUNCH OF PLACES BELOW
  set $my_site "54.84.155.107";

  listen 80;
  server_name $my_site;

  # HERE IS A GOOD PLACE TO FORCE CANONICAL DOMAIN
  if ( $host != '$my_site' ) {
   rewrite ^/(.*)$ http://$my_site/$1 permanent;
  }
  access_log /var/log/nginx/my_site.access_log;
  error_log /var/log/nginx/my_site.error_log;

  #root /var/www/www.domain.tld;
  root /usr/share/nginx/www/my-nginx-rewrite-rules/current;
  index index.php index.htm index.html;

  # serve static files directly
  location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml|txt)$ {
    access_log off;
    expires 30d;
  }

  location ~ /(config\.php|common\.php|cache|files|images/avatars/upload|includes|store) {
    deny all;
    return 403;
  }

  # ADDS SUPPORT FOR PHPBB TO NGINX
  location ~ .php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/www/my-nginx-rewrite-rules/current$fastcgi_script_name;
    include fastcgi_params;
    try_files $uri =404;
  }

  location /images {
    root /usr/share;
    autoindex on;
  }

  location = /50x.html {
    #root /usr/share/nginx/www;
    root /usr/share/nginx/www/my-nginx-rewrite-rules/current;
  }


#begin SEO secton
# Need to translate the deny
# THIS DIRECTIVE DOES NOT WORK. CAUSES A 404 ERROR
  # DO NOT GO FURTHER does  THE REQUESTED FILE / folder DOES EXISTS
#  if (!-e $request_filename) {
#    rewrite . - last;
#  }
  #####################################################
  # PHPBB SEO REWRITE RULES ALL MODES
  #####################################################

  location / {

  # FORUMS PAGES
  ###############
  # FORUM INDEX
  rewrite ^/forum\.html$ /forums2/index.php last;

  # FORUM ALL MODES
  rewrite ^/(forum|[a-z0-9_-]*-f)([0-9]+)(-([0-9]+))?\.html$ /forums2/viewforum.php?f=$2&start=$4 last;

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

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

  # PHPBB FILES ALL MODES
  rewrite ^/resources/[a-z0-9_-]+/(thumb/)?([0-9]+)$ /forums2/download/file.php?id=$2&t=$1 last;

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

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

  # GROUPS ALL MODES
  rewrite ^/(group|[a-z0-9_-]*-g)([0-9]+)(-([0-9]+))?\.html$ /forums2/memberlist.php?mode=group&g=$2&start=$4 last;

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

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

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

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

  # UNREAD POSTS
  rewrite ^/unreadposts(-([0-9]+))?\.html$ /forums2/search.php?search_id=unreadposts&start=$2 last;

  # THE TEAM
  rewrite ^/the-team\.html$ /forums2/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)+)?/?$ /forums2/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)?$ /forums2/map.php?$1&start=$3 last;
  # END GYM Sitemaps & RSS
  #####################################################



  # 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

  if (!-f $request_filename) {
    rewrite ^/([a-z0-9_-]+)(-([0-9]+))\.html$ /forums2/viewforum.php?forum_uri=$1&start=$3 last;
  }

  if (!-f $request_filename) {
    rewrite ^/([a-z0-9_-]+)\.html$ /forums2/viewforum.php?forum_uri=$1 last;
  }

  # FIX RELATIVE PATHS : FILES
  rewrite ^/forums2/.+/(style\.php|ucp\.php|mcp\.php|faq\.php|download/file.php)$ /forums2/$1 last;

  # FIX RELATIVE PATHS : IMAGES
  rewrite ^/forums2/.+/(styles/.*|images/.*)/$ /forums2/$1 last;

  # END PHPBB PAGES
  #####################################################

  }
 
  #Adds the ability to use the virtual folder by adding an nginx way to do a multiview
  # This one works with html extensions
  location ~ ^(.+)/$ {
    try_files $uri $1.html?$args;
  }

}
bweston1a
 
Posts: 8
Joined: Thu May 12, 2011 11:33 pm


Return to phpBB mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 10 guests