lighttpd rewrite rules for SMF Pretty Urls mod
Added by sipiatti almost 16 years ago
Hi,
I several times installed SMF forum system (http://www.simplemachines.org) and its favorite SEO mod Pretty Urls. It works almost out-of-the-box with Apache, and also I managed it on nginx webserver. Now I have a task to apply it on a lighttpd server. I've read the docs how I need to construct the rewrite rules. The site is http://currate.com/forums/index.php
The original apache rules are the following:- PRETTYURLS MOD BEGINS
- Pretty URLs mod
- http://code.google.com/p/prettyurls/
- .htaccess file generated automatically on: July 9, 2009, 13:15
RewriteEngine on
RewriteBase /~sipiatti/smf
- Rules for: boards
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1.0 [L,QSA]
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/?$ ./index.php?pretty;board=$1.$2 [L,QSA]
- Rules for: topics
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1;topic=$2.0 [L,QSA]
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ ./index.php?pretty;board=$1;topic=$2.$3 [L,QSA]
- PRETTYURLS MOD ENDS
My constructed rules for lighttpd are:
"^/forums/([-_!~*'()$a-zA-Z0-9]+)(\?(.*))?/?$" => "/forums/index.php?pretty;board=$1.0$2",
"^/forums/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)(\?(.*))?/?$" => "/forums/index.php?pretty;board=$1.$2$3",
"^/forums/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)(\?(.*))?/?$" => "/forums/index.php?pretty;board=$1;topic=$2.0$3",
"^/forums/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)(\?(.*))?/?$" => "/forums/index.php?pretty;board=$1;topic=$2.$3$4"
I tried to apply the querystring backreferences. It works almost good, but there are links what are do not.
I have problems with urls what have apostroph in them. They just do not work.
Also I have problems if an url what is ok with rewrite has query string. e.g.: http://currate.com/forums/forum-rules/?action=markasread;sa=board;sesc=ae822175b25631c77ff5ddfededebd0c
Can someone with lighttpd rewrite experience look through the aboves?
Thanks in advance.
sipiatti
Replies (2)
RE: lighttpd rewrite rules for SMF Pretty Urls mod - Added by MikiB over 15 years ago
Here is my solution for SMF Pretty Urls 1-0RCb. Hope will someone be helpful.
Works on my forum, implemented as is on Kloxo admin panel. You can paste code directly to lighttpd.domain.conf file.
Original apache .htaccess file:
# Rules for: profiles RewriteRule ^profile/([^/]+)/?$ ./index.php?pretty;action=profile;user=$1 [L,QSA] # Rules for: actions RewriteRule ^(activate|admin|ads|announce|attachapprove|buddy|calendar|clock)/?$ ./index.php?pretty;action=$1 [L,QSA] RewriteRule ^(collapse|coppa|credits|deletemsg|display|dlattach|editpoll|editpoll2)/?$ ./index.php?pretty;action=$1 [L,QSA] RewriteRule ^(emailuser|findmember|groups|help|helpadmin|im|jseditor|jsmodify)/?$ ./index.php?pretty;action=$1 [L,QSA] RewriteRule ^(jsoption|lock|lockvoting|login|login2|logout|markasread|mascot)/?$ ./index.php?pretty;action=$1 [L,QSA] RewriteRule ^(mergetopics|mlist|moderate|modifycat|modifykarma|movetopic|movetopic2|notify)/?$ ./index.php?pretty;action=$1 [L,QSA] RewriteRule ^(notifyboard|openidreturn|pm|post|post2|printpage|profile|quotefast)/?$ ./index.php?pretty;action=$1 [L,QSA] RewriteRule ^(quickmod|quickmod2|recent|register|register2|reminder|removepoll|removetopic2)/?$ ./index.php?pretty;action=$1 [L,QSA] RewriteRule ^(reporttm|requestmembers|restoretopic|search|search2|sendtopic|smstats|suggest)/?$ ./index.php?pretty;action=$1 [L,QSA] RewriteRule ^(spellcheck|splittopics|stats|sticky|theme|trackip|about:mozilla|about:unknown)/?$ ./index.php?pretty;action=$1 [L,QSA] RewriteRule ^(unread|unreadreplies|verificationcode|viewprofile|vote|viewquery|viewsmfile|who)/?$ ./index.php?pretty;action=$1 [L,QSA] RewriteRule ^(\.xml|xmlhttp)/?$ ./index.php?pretty;action=$1 [L,QSA] # Rules for: boards RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1.0 [L,QSA] RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/?$ ./index.php?pretty;board=$1.$2 [L,QSA] # Rules for: topics RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1;topic=$2.0 [L,QSA] RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ ./index.php?pretty;board=$1;topic=$2.$3 [L,QSA]
My Lighttpd rewrite code:
url.rewrite-once = ( # Rules for: profiles "^/profile/([^/]+)/(?:\?(.*))?$" => "/index.php?pretty;action=profile;u=$1;$2", # Rules for: actions "^/(activate|admin|ads|announce|attachapprove|buddy|calendar|clock)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(collapse|coppa|credits|deletemsg|display|dlattach|editpoll|editpoll2)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(emailuser|findmember|groups|help|helpadmin|im|jseditor|jsmodify)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(jsoption|lock|lockvoting|login|login2|logout|markasread|mascot)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(mergetopics|mlist|moderate|modifycat|modifykarma|movetopic|movetopic2|notify)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(notifyboard|openidreturn|pm|post|post2|printpage|profile|quotefast)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(quickmod|quickmod2|recent|register|register2|reminder|removepoll|removetopic2)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(reporttm|requestmembers|restoretopic|search|search2|sendtopic|smstats|suggest)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(spellcheck|splittopics|stats|sticky|theme|trackip|about:mozilla|about:unknown)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(unread|unreadreplies|verificationcode|viewprofile|vote|viewquery|viewsmfile|who)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(\.xml|xmlhttp)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", # Rules for: boards "^/([-_!~*'()$a-zA-Z0-9]+)/(?:\?(.*))?$" => "/index.php?pretty;board=$1.0;$2, "^/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/(?:\?(.*))?$" => "/index.php?pretty;board=$1.$2;$3, # Rules for: topics "^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/(?:\?(.*))?$" => "/index.php?pretty;board=$1;topic=$2.0;$3, "^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/(?:\?(.*))?$" => "/index.php?pretty;board=$1;topic=$2.$3;$4 )
RE: lighttpd rewrite rules for SMF Pretty Urls mod - Added by tdev about 15 years ago
the updated rewrite rules for "prettyurls-1-0RCb-SMF2RC2.zip" SMF-2 RC2:
(also added some handy expire thing):
$HTTP["host"] == "forum.yourdomain.com" { url.rewrite-once = ( "^/(Themes|Smileys|avatars|Packages|awards|geshi|mathtex|pm_attachments)/(.*)?$" => "/$1/$2", # Rules for: profiles "^/profile/([^/]+)/(?:\?(.*))?$" => "/index.php?pretty;action=profile;user=$1;$2", "^/profile/([^/]+)?$" => "/index.php?pretty;action=profile;user=$1", # Rules for: actions "^/(activate|admin|ads|announce|attachapprove|buddy|calendar|clock)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(collapse|coppa|credits|deletemsg|display|dlattach|dlpmattach|editpoll)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(editpoll2|emailuser|findmember|groups|help|helpadmin|im|jseditor)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(jsmodify|jsoption|lock|lockvoting|login|login2|logout|markasread)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(mergetopics|mlist|moderate|modifycat|modifykarma|viewkarma|ownkarma|otherkarma)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(movetopic|movetopic2|notify|notifyboard|openidreturn|pm|post|post2)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(printpage|profile|quotefast|quickmod|quickmod2|recent|register|register2)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(reminder|removepoll|removetopic2|reporttm|requestmembers|restoretopic|search|search2)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(sendtopic|smstats|suggest|spellcheck|splittopics|stats|sticky|theme)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(topicattach|trackip|about:mozilla|about:unknown|unread|unreadreplies|verificationcode|viewprofile)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", "^/(vote|viewquery|viewsmfile|who|\.xml|xmlhttp)/(?:\?(.*))?$" => "/index.php?pretty;action=$1;$2", # Rules for: boards "^/([-_!~*'()$a-zA-Z0-9]+)/(?:\?(.*))?$" => "/index.php?pretty;board=$1.0;$2", "^/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/(?:\?(.*))?$" => "/index.php?pretty;board=$1.$2;$3", # Rules for: topics "^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/(?:\?(.*))?$" => "/index.php?pretty;board=$1;topic=$2.0;$3", "^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/(?:\?(.*))?$" => "/index.php?pretty;board=$1;topic=$2.$3;$4", ) # expire for themes and static contents expire.url = ( "/Themes/" => "access 2 weeks" , "/Smileys/" => "access 2 weeks" , "/avatars/" => "access 2 weeks") }