News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

SMF 2.0 and nginx (human-readable URL)

Started by cyberbat, April 18, 2013, 09:21:16 AM

Previous topic - Next topic

cyberbat

I use nginx + php-fpm on my server and I was really confused that human-readable urls are not supported by SMF on this configuration and there is no docs about it on this forum. So I've found in russian blog post about it. I hope that some time in the future SMF will support nginx out of the box.

So there is instructions:

First edit nginx.conf, place this in 'server' block (I've changed ^/index\.php/ to ^/forum/index\.php/ cause I have forum in /forum/ subdirectory):

UPDATED (according to this message)
rewrite ^/index\.php/([a-z]+),([0-9]+)\.(\w+)/(\w+),(\w+)/(\w+)\.html /index.php?$1=$2.$3&$4=$5&$6 last;
rewrite ^/index\.php/([a-z]+),([0-9]+)\.(\w+)/(\w+),(\w+)\.html /index.php?$1=$2.$3&$4=$5 last;
rewrite ^/index\.php/([a-z]+),([0-9]+)\.(\w+)/(\w+)/(\w+)\.html /index.php?$1=$2.$3&$4&$5 last;
rewrite ^/index\.php/([a-z]+),([0-9]+)\.(\w+)/(\w+)\.html /index.php?$1=$2.$3&$4 last;
rewrite ^/index\.php/([a-z]+),([0-9]+)\.(\w+)\.html /index.php?$1=$2.$3 last;
rewrite ^/index\.php/([a-z]+),([0-9]+\.\d)\.(\w+)\.html /forum/index.php?$1=$2.$3 last;
rewrite ^/index\.php/([a-z]+),([0-9]+)/(\w+),(\w+)\.html /forum/index.php?$1=$2&$3=$4 last;


It's pity, but SMF turn off human-readable URLs in the code when it doesn't see apache or lighttpd, so we have to edit some source file. I clearly guess that it's really dirty hack and will be glad if somebody give me more beautiful variant.

Open Sources/QueryString.php, look for function ob_sessrewrite and change string in it from
if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || @ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd']))

to

if (true || !empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || @ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd']))

Save the file and that's all. Human-readable URLs should work OK.

Arantor

The queryless URLs setting is disabled because it's not supported out of the box except on those servers. It isn't possible to support that in nginx without rewrite rules - which SMF doesn't support itself for the obvious reason that it has absolutely no ability to control them.

And it's hardly 'human readable'. index.php?topic=1.0 vs index.php/topic,1.0.html is not a significant change. It will also tank any SEO you already had.

cyberbat

Quote from: Arantor on April 18, 2013, 09:24:07 AM
It isn't possible to support that in nginx without rewrite rules - which SMF doesn't support itself for the obvious reason that it has absolutely no ability to control them.

May be SMF can check whether index.php/topic,1.0.html is accesible and disable queryless URLs only when not?

Quote from: Arantor on April 18, 2013, 09:24:07 AM
And it's hardly 'human readable'. index.php?topic=1.0 vs index.php/topic,1.0.html is not a significant change. It will also tank any SEO you already had.

Sorry, it's my english problem. I'm russian speaker and in russian we say human-readable url for all queryless SEO optimized URLs. And excuse me but I can't understand the word "tank" here. Do index.php/topic,1.0.html make better or worse for SEO?

Arantor

QuoteAnd excuse me but I can't understand the word "tank" here.

Tank in this context means really screw up. You already have search engine traffic, yes? Changing all the URLs will destroy anything you currently have.

QuoteDo index.php/topic,1.0.html make better or worse for SEO?

They do absolutely nothing to improve SEO as compared to index?topic=1.0

Several years ago when SMF first debuted, it made a huge difference. But that was a decade ago, it's not been a big issue for some years.

cyberbat

Quote from: Arantor on April 19, 2013, 08:50:39 AM
QuoteAnd excuse me but I can't understand the word "tank" here.

Tank in this context means really screw up. You already have search engine traffic, yes? Changing all the URLs will destroy anything you currently have.

QuoteDo index.php/topic,1.0.html make better or worse for SEO?

They do absolutely nothing to improve SEO as compared to index?topic=1.0

Several years ago when SMF first debuted, it made a huge difference. But that was a decade ago, it's not been a big issue for some years.

I move forum from apache+mod_php to nginx+php-fpm, so there will be changing if I will not make queryless URLs. Thank you for your explanation.

cyberbat

After some time of successfull use of my forum, I've got following problem:
When I watch attachement list from admin panel (/forum/index.php?action=admin;area=manageattachments;sa=browse) I got links on messages with attachements in such form: /forum/index.php/topic,238.0.msg330.html#msg330 (pay attention to topic number: 238.0). These links break my rewrite rules (from first message) for queryless URLs.
I've fixed this by adding one line to the rules:
rewrite ^/forum/index\.php/([a-z]+),([0-9]+\.\d)\.(\w+)\.html /forum/index.php?$1=$2.$3 last;

But I want to ask:
1) What is the meaning of this additional digit? I have not get it other then 0.
2) Am I right with additional rewrite rule?

vietravel247.com

I modify my nginx.conf like this:
location  / {
       # Rules for: actions
          rewrite ^/(activate|admin|ads|announce|attachapprove|ban|boardrecount|buddy|calendar|clock)/?$ "/index.php?pretty;action=$1" last;
           rewrite ^/(collapse|convertentities|coppa|credits|deletemsg|detailedversion|display|dlattach|editpoll|editpoll2)/?$ "/index.php?pretty;action=$1" last;
           rewrite ^/(emailuser|featuresettings|findmember|groups|help|helpadmin|im|jseditor|jsmodify)/?$ "/index.php?pretty;action=$1" last;
           rewrite ^/(jsoption|lock|lockvoting|login|login2|logout|manageboards|managecalendar|managesearch|manageattachments|maintain|markasread|mascot)/?$ "/index.php?pretty;action=$1" last;
          rewrite ^/(membergroups|mergetopics|mlist|moderate|modifycat|modifykarma|movetopic|movetopic2|news|notify)/?$ "/index.php?pretty;action=$1" last;
          rewrite ^/(notifyboard|optimizetables|openidreturn|packages|permissions|pm|post|postsettings|post2|printpage|profile|quotefast)/?$ "/index.php?pretty;action=$1" last;
          rewrite ^/(quickmod|quickmod2|recent|regcenter|register|register2|reminder|removepoll|removetopic2)/?$ "/index.php?pretty;action=$1" last;
          rewrite ^/(repairboards|reporttm|requestmembers|restoretopic|reports|search|search2|sendtopic|serversettings|smileys|smstats|suggest)/?$ "/index.php?pretty;action=$1" last;
          rewrite ^/(spellcheck|splittopics|stats|sticky|theme|trackip|about:mozilla|about:unknown)/?$ "/index.php?pretty;action=$1" last;
          rewrite ^/(unread|unreadreplies|verificationcode|viewErrorLog|viewmembers|viewprofile|vote|viewquery|viewsmfile|who)/?$ "/index.php?pretty;action=$1" last;
          rewrite ^/(\.xml|xmlhttp)/?$ "//index.php?pretty;action=$1" last;
       # Rules for: boards & Topics
          rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/?$ "/index.php?pretty;board=$1.0" last;
          rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/?$ "/index.php?pretty;board=$1.$2" last;
          rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ "/index.php?pretty;board=$1;topic=$2.0" last;
          rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ "/index.php?pretty;board=$1;topic=$2.$3" last;

          rewrite ^/index.php/board,([0-9]+).0.html /index.php?board=$1.0 last;
          rewrite ^/index.php/topic,([0-9]+).0.html /index.php?topic=$1.0 last;
          rewrite ^/index.php/topic,([0-9]+).msg([0-9]+).html /index.php?topic=$1.msg$2 last;
}

and it's ok (Demo: http://hoidulich.com).

cyberbat

New update for rewrite rules, quick answer fix:

rewrite ^/forum/index\.php/([a-z]+),([0-9]+)/(\w+),(\w+)\.html /forum/index.php?$1=$2&$3=$4 last;

1Chope

Sorry for bumping this old topic, I got this in Google search and I just don't want to create a new topic for this.
Seriously, I don't know why SMF will not retire the old school  forumname/index.php?topic=167359.0 to something like this forumname/topic-167359? This is human readable and I even prefer it to the pretty Url. That is what mybb is using, something like forumname.com/thread-1234.html and some topic I create which I did not bookmark is easily navigated to me by just adding the topic number with the closing .html.
I also think every forum software should now be supporting Nginx config as most forum owners are have and are still migrating to Nginx.
Thanks.

Advertisement: