MyBB Community Forums

Full Version: [Nginx] Enabling Search Engine Friendly URLs
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
My VPS: 512MB Ram 20GB SSD Disk CentOS 6.5 x64, installed Centminmod(include: NGINX, PHP-FPM and MariaDB)
MyBB version: 1.6.15

I use these rules in block: location /{ ... }

Quote:        # GOOGLE SEO PLUGIN 1.6.8
        # Google SEO workaround for search.php highlights:

        # Make this rule the first rewrite rule in your .htaccess!
        rewrite ^/([^&]*)&(.*)$ http://myforum.com/$1?$2 permanent;

        # Google SEO Sitemap:
        rewrite ^/((?i)sitemap-([^./]+)\.xml)$ /misc.php?google_seo_sitemap=$2;

        # Google SEO URL Forums:
        rewrite ^/((?i)Forum-([^./]+))$ /forumdisplay.php?google_seo_forum=$2;

        # Google SEO URL Threads:
        rewrite ^/((?i)Thread-([^./]+))$ /showthread.php?google_seo_thread=$2;

        # Google SEO URL Announcements:
        rewrite ^/((?i)Announcement-([^./]+))$ /announcements.php?google_seo_announcement=$2;

        # Google SEO URL Users:
        rewrite ^/((?i)User-([^./]+))$ /member.php?action=profile&google_seo_user=$2;

        # Google SEO URL Calendars:
        rewrite ^/((?i)Calendar-([^./]+))$ /calendar.php?google_seo_calendar=$2;

        # Google SEO URL Events:
        rewrite ^/((?i)Event-([^./]+))$ /calendar.php?action=event&google_seo_event=$2;

I go to Plugins -> Google SEO plugin -> click to Apply and my forum's URL like:
Quote:http://myforum.com/Forum-General-Support

http://myforum.com/Thread-[Nginx]-Enabling-Search-Engine-Friendly-URLs


My forum rewrite URL seem to be OK:


Quote:When I type: http://myforum.com/forumdisplay.php?fid=132
Redirect to: http://myforum.com/Forum-General-Support

or

http://myforum.com/showthread.php?tid=47...n=lastpost
Redirect to:
http://myforum.com/Thread-[Nginx]-Enabling-Search-Engine-Friendly-URLs?pid=1127#pid1127


The problem is: 
My forum won't redirect me to the forum with URL like this:
Quote:http://myforum.com/thread-132.html
or
http://myforum.com/thread-47-lastpost.html
or
http://myforum.com/forum-132.html

It returns 404 Not Found nginx

I found frostschutz's guide: http://community.mybb.com/thread-51764.html
Then I changed rules in location block to:

Quote:location / {
# ...your location settings are here... r

rewrite ^/forum-([0-9]+)\.html$ /forumdisplay.php?fid=$1;

    rewrite ^/forum-([0-9]+)-page-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2;
    rewrite ^/thread-([0-9]+)\.html$ /showthread.php?tid=$1;
    rewrite ^/thread-([0-9]+)-page-([0-9]+)\.html$ /showthread.php?tid=$1&page=$2;
    rewrite ^/thread-([0-9]+)-lastpost\.html$ /showthread.php?tid=$1&action=lastpost;
    rewrite ^/thread-([0-9]+)-nextnewest\.html$ /showthread.php?tid=$1&action=nextnewest;
    rewrite ^/thread-([0-9]+)-nextoldest\.html$ /showthread.php?tid=$1&action=nextoldest;
    rewrite ^/thread-([0-9]+)-newpost\.html$ /showthread.php?tid=$1&action=newpost;
    rewrite ^/thread-([0-9]+)-post-([0-9]+)\.html$ /showthread.php?tid=$1&pid=$2;
    rewrite ^/post-([0-9]+)\.html$ /showthread.php?pid=$1;
    rewrite ^/announcement-([0-9]+)\.html$ /announcements.php?aid=$1;
    rewrite ^/user-([0-9]+)\.html$ /member.php?action=profile&uid=$1;
    rewrite ^/calendar-([0-9]+)\.html$ /calendar.php?calendar=$1;
    rewrite ^/calendar-([0-9]+)-year-([0-9]+)\.html$ /calendar.php?action=yearview&calendar=$1&year=$2;
    rewrite ^/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ /calendar.php?calendar=$1&year=$2&month=$3;
    rewrite ^/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ /calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4;
    rewrite ^/calendar-([0-9]+)-week-(n?[0-9]+)\.html$ /calendar.php?action=weekview&calendar=$1&week=$2;
    rewrite ^/event-([0-9]+)\.html$ /calendar.php?action=event&eid=$1;

}

I go to Configuration->Settings->Server and Optimization Options->Enable search engine friendly URLs? set to Enabled.
Restart Nginx -> OK

BUT everything seems worse! I get 404 errors when clicking on thread / forum links as frostschutz said.

Now I don't know how to solve this problem! Help me please, thanks everyone!


(PS: Sorry for my bad English)
I have the same problem, Google SEO plugin doesn't work when I move my forum from Hostgator to Digitalocean(using VPS).
Anyone can solve this??? Thank so much!
Disappointed! There's no one can help us!!! I don't want to asking anyone anymore, I think I will solve it for myself, I will show you when I found the method to solve it. Wait for me!
if you want to support both types of urls (forum-123.html and Forum-Shrivelfigs) then you need both sets of rewrites too, not just one or the other...
(2014-11-09, 08:39 PM)frostschutz Wrote: [ -> ]if you want to support both types of urls (forum-123.html and Forum-Shrivelfigs) then you need both sets of rewrites too, not just one or the other...
Yes, I both set of rewrites and I am sure that I did exactly what you said! But no works.

My server block(myforum.com.conf):

 

Quote:server {
            listen   80;
            server_name www.myforum.com;
                rewrite ^(.*) http://myforum.com$1 permanent;

#            return 301 $scheme://www.myforum.com$request_uri;
       }

server {
  server_name myforum.com;

# ngx_pagespeed & ngx_pagespeed handler
include /usr/local/nginx/conf/pagespeed.conf;
include /usr/local/nginx/conf/pagespeedhandler.conf;
include /usr/local/nginx/conf/pagespeedstatslog.conf;

  # limit_conn limit_per_ip 16;
  # ssi  on;

  access_log /home/nginx/domains/myforum.com/log/access.log combined buffer$
  error_log /home/nginx/domains/myforum.com/log/error.log;

  root /home/nginx/domains/myforum.com/public;



location / {

# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;

  # Enables directory listings when index file not found
  #autoindex  on;

  # Shows file listing times as local time
  #autoindex_localtime on;

  # Enable for vBulletin usage WITHOUT vbSEO installed
  #try_files            $uri $uri/ /index.php;

  rewrite ^/forum-([0-9]+)\.html$ /forumdisplay.php?fid=$1;
    rewrite ^/forum-([0-9]+)-page-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2;
    rewrite ^/thread-([0-9]+)\.html$ /showthread.php?tid=$1;
    rewrite ^/thread-([0-9]+)-page-([0-9]+)\.html$ /showthread.php?tid=$1&page=$2;
    rewrite ^/thread-([0-9]+)-lastpost\.html$ /showthread.php?tid=$1&action=lastpost;
    rewrite ^/thread-([0-9]+)-nextnewest\.html$ /showthread.php?tid=$1&action=nextnewest;
    rewrite ^/thread-([0-9]+)-nextoldest\.html$ /showthread.php?tid=$1&action=nextoldest;
    rewrite ^/thread-([0-9]+)-newpost\.html$ /showthread.php?tid=$1&action=newpost;
    rewrite ^/thread-([0-9]+)-post-([0-9]+)\.html$ /showthread.php?tid=$1&pid=$2;
    rewrite ^/post-([0-9]+)\.html$ /showthread.php?pid=$1;
    rewrite ^/announcement-([0-9]+)\.html$ /announcements.php?aid=$1;
    rewrite ^/user-([0-9]+)\.html$ /member.php?action=profile&uid=$1;
    rewrite ^/calendar-([0-9]+)\.html$ /calendar.php?calendar=$1;
    rewrite ^/calendar-([0-9]+)-year-([0-9]+)\.html$ /calendar.php?action=yearview&calendar=$1&year=$2;
    rewrite ^/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ /calendar.php?calendar=$1&year=$2&month=$3;
    rewrite ^/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ /calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4;
    rewrite ^/calendar-([0-9]+)-week-(n?[0-9]+)\.html$ /calendar.php?action=weekview&calendar=$1&week=$2;
    rewrite ^/event-([0-9]+)\.html$ /calendar.php?action=event&eid=$1;

        
        # GOOGLE SEO PLUGIN 1.6.8
        # Google SEO workaround for search.php highlights:

        # Make this rule the first rewrite rule in your .htaccess!
        rewrite ^/([^&]*)&(.*)$ http://myforum.com/$1?$2 permanent;

        # Google SEO Sitemap:
        rewrite ^/((?i)sitemap-([^./]+)\.xml)$ /misc.php?google_seo_sitemap=$2;

        # Google SEO URL Forums:
        rewrite ^/((?i)Forum-([^./]+))$ /forumdisplay.php?google_seo_forum=$2;

        # Google SEO URL Threads:
        rewrite ^/((?i)Thread-([^./]+))$ /showthread.php?google_seo_thread=$2;

        # Google SEO URL Announcements:
        rewrite ^/((?i)Announcement-([^./]+))$ /announcements.php?google_seo_announcement=$2;

        # Google SEO URL Users:
        rewrite ^/((?i)User-([^./]+))$ /member.php?action=profile&google_seo_user=$2;

        # Google SEO URL Calendars:
        rewrite ^/((?i)Calendar-([^./]+))$ /calendar.php?google_seo_calendar=$2;

        # Google SEO URL Events:
        rewrite ^/((?i)Event-([^./]+))$ /calendar.php?action=event&google_seo_event=$2;

}
}

I still find the method to fix it. Thank you very much for replying! You're good man, if I was a girl I will force you to be my boyfriend  Big Grin 

Hi all,

I fixed this problem! DO NOT place the rules into the location block, place them inside server block, here is my config file:


Quote:server {

rewrite ^/forum-([0-9]+).html$ /forumdisplay.php?fid=$1 last;

rewrite ^/forum-([0-9]+)-page-([0-9]+).html$ /forumdisplay.php?fid=$1&page=$2 last;
rewrite ^/thread-([0-9]+).html$ /showthread.php?tid=$1 last;
rewrite ^/thread-([0-9]+)-page-([0-9]+).html$ /showthread.php?tid=$1&page=$2 last;
rewrite ^/thread-([0-9]+)-lastpost.html$ /showthread.php?tid=$1&action=lastpost last;
rewrite ^/thread-([0-9]+)-nextnewest.html$ /showthread.php?tid=$1&action=nextnewest last;
rewrite ^/thread-([0-9]+)-nextoldest.html$ /showthread.php?tid=$1&action=nextoldest last;
rewrite ^/thread-([0-9]+)-newpost.html$ /showthread.php?tid=$1&action=newpost last;
rewrite ^/thread-([0-9]+)-post-([0-9]+).html$ /showthread.php?tid=$1&pid=$2 last;
rewrite ^/post-([0-9]+).html$ /showthread.php?pid=$1 last;
rewrite ^/announcement-([0-9]+).html$ /announcements.php?aid=$1 last;
rewrite ^/user-([0-9]+).html$ /member.php?action=profile&uid=$1 last;
rewrite ^/calendar-([0-9]+).html$ /calendar.php?calendar=$1 last;
rewrite ^/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+).html$ /calendar.php?calendar=$1&year=$2&month=$3 last;
rewrite ^/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+).html$ /calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4 last;
rewrite ^/calendar-([0-9]+)-week-(n?[0-9]+).html$ /calendar.php?action=weekview&calendar=$1&week=$2 last;
rewrite ^/event-([0-9]+).html$ /calendar.php?action=event&eid=$1 last;

}