[lighttpd] Enabling Search Engine Friendly URLs
#1
Pencil 
This user has been denied support. This user has been denied support.
If you are using lighttpd ("lighty") instead of Apache web server, this tutorial explains how you can enable MyBB's Search Engine Friendly SEF URLs. Apache users do not need to read this tutorial.

This tutorial does not explain how to install and set up lighttpd with PHP from scratch; it is expected that you already have everything up and running, and now all that's left are the SEF URLs.

lighttpd.conf

First you should make a backup copy of your lighttpd.conf, so you can go back to your working config in case anything goes wrong.

In the modules section, enable mod_rewrite:

server.modules = (
    # ...other modules go here...

    "mod_rewrite",
)

In the mod_rewrite section, add these rewrite rules. Replace /MyBB/ with the directory you have MyBB installed. If your MyBB is installed in a top level domain, replace it with /, if it's in /forum replace it with /forum/ and so on.

Please note that everything in the quotes "" goes in a single line even if it wraps in your browser here.

url.rewrite = (
    # ...other rewrite rules go here...

    "^/MyBB/forum-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/forumdisplay.php?fid=$1&$3",
    "^/MyBB/forum-([0-9]+)-page-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/forumdisplay.php?fid=$1&page=$2&$4",
    "^/MyBB/thread-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/showthread.php?tid=$1&$3",
    "^/MyBB/thread-([0-9]+)-page-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/showthread.php?tid=$1&page=$2&$4",
    "^/MyBB/thread-([0-9]+)-lastpost\.html(\?(.*)|)$" => "/MyBB/showthread.php?tid=$1&action=lastpost&$3",
    "^/MyBB/thread-([0-9]+)-nextnewest\.html(\?(.*)|)$" => "/MyBB/showthread.php?tid=$1&action=nextnewest&$3",
    "^/MyBB/thread-([0-9]+)-nextoldest\.html(\?(.*)|)$" => "/MyBB/showthread.php?tid=$1&action=nextoldest&$3",
    "^/MyBB/thread-([0-9]+)-newpost\.html(\?(.*)|)$" => "/MyBB/showthread.php?tid=$1&action=newpost&$3",
    "^/MyBB/thread-([0-9]+)-post-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/showthread.php?tid=$1&pid=$2&$4",

    "^/MyBB/post-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/showthread.php?pid=$1&$3",

    "^/MyBB/announcement-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/announcements.php?aid=$1&$3",

    "^/MyBB/user-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/member.php?action=profile&uid=$1&$3",

    "^/MyBB/calendar-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/calendar.php?calendar=$1&$3",
    "^/MyBB/calendar-([0-9]+)-year-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/calendar.php?action=yearview&calendar=$1&year=$2&$4",
    "^/MyBB/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/calendar.php?calendar=$1&year=$2&month=$3&$5",
    "^/MyBB/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4&$6",
    "^/MyBB/calendar-([0-9]+)-week-(n?[0-9]+)\.html(\?(.*)|)$" => "/MyBB/calendar.php?action=weekview&calendar=$1&week=$2&$4",

    "^/MyBB/event-([0-9]+)\.html(\?(.*)|)$" => "/MyBB/calendar.php?action=event&eid=$1&$3",
)

Restart lighttpd so the changes can take effect.

MyBB settings

In Admin CP, go to 'Configuration' -> 'Server and Optimization options' and set 'Enable search engine friendly URLs?' to 'Enabled'.
(The auto detect option will not work with lighttpd.)

Go back into your forum and test if the MyBB SEF URLs work.

Troubleshooting
  • lighttpd refuses to start
    You probably made an error when editing the config file; lighttpd should tell you where the error is, correct it.
  • I get 404 errors when clicking on thread / forum links
    Your rewrite rules are not working. Maybe you used the wrong path (in the example /MyBB/). Replace it with the correct path, for example / or /forum/. Also check if you forgot to enable/install the mod_rewrite module.
Reply
#2
Excellent ...!
Reply
#3
this is /etc/lighttpd/lighttpd.conf which forum installing on root.
Re-Write Wink

url.rewrite = (
    # ...other rewrite rules go here...

    "^/forum-([0-9]+)\.html(\?(.*)|)$" => "/forumdisplay.php?fid=$1&$3",
    "^/forum-([0-9]+)-page-([0-9]+)\.html(\?(.*)|)$" => "/forumdisplay.php?fid=$1&page=$2&$4",
    "^/thread-([0-9]+)\.html(\?(.*)|)$" => "/showthread.php?tid=$1&$3",
    "^/thread-([0-9]+)-page-([0-9]+)\.html(\?(.*)|)$" => "/showthread.php?tid=$1&page=$2&$4",
    "^/thread-([0-9]+)-lastpost\.html(\?(.*)|)$" => "/showthread.php?tid=$1&action=lastpost&$3",
    "^/thread-([0-9]+)-nextnewest\.html(\?(.*)|)$" => "/showthread.php?tid=$1&action=nextnewest&$3",
    "^/thread-([0-9]+)-nextoldest\.html(\?(.*)|)$" => "/showthread.php?tid=$1&action=nextoldest&$3",
    "^/thread-([0-9]+)-newpost\.html(\?(.*)|)$" => "/showthread.php?tid=$1&action=newpost&$3",
    "^/thread-([0-9]+)-post-([0-9]+)\.html(\?(.*)|)$" => "/showthread.php?tid=$1&pid=$2&$4",

    "^/post-([0-9]+)\.html(\?(.*)|)$" => "/showthread.php?pid=$1&$3",

    "^/announcement-([0-9]+)\.html(\?(.*)|)$" => "/announcements.php?aid=$1&$3",

    "^/user-([0-9]+)\.html(\?(.*)|)$" => "/member.php?action=profile&uid=$1&$3",

    "^/calendar-([0-9]+)\.html(\?(.*)|)$" => "/calendar.php?calendar=$1&$3",
    "^/calendar-([0-9]+)-year-([0-9]+)\.html(\?(.*)|)$" => "/calendar.php?action=yearview&calendar=$1&year=$2&$4",
    "^/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html(\?(.*)|)$" => "/calendar.php?calendar=$1&year=$2&month=$3&$5",
    "^/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&$6",
    "^/calendar-([0-9]+)-week-(n?[0-9]+)\.html(\?(.*)|)$" => "/calendar.php?action=weekview&calendar=$1&week=$2&$4",

    "^/event-([0-9]+)\.html(\?(.*)|)$" => "/calendar.php?action=event&eid=$1&$3",
)
Hello, Welcome to MyBB Indonesia to get local support
My 'Simple' Unique Plugin here Smile
Reply
#4
Really cool bro, I might switch from Apache to lighttpd.
Reply
#5
is there anyway where i can use thread name in url.

i run on cpanel..

sorry if out of topic

Guide to bank accounts, credit cards and investments.
Reply
#6
I answered your post in the 2 and a half year old thread you bumped.

http://mods.mybboard.net/view/google-seo
MyReactions - All Plugins

Can you still feel the butterflies?

Free never tasted like pudding.
Reply
#7
I find this:

when Google catch link -http://forum.com/thread-77024.html (for example)
and when clicked forwarding to -http://forum.com/showthread.php?tid=77024& (& sign at the end)
but still work, if manually pointing to -http://www.forum.com/thread-77024.html

I am using this, before.
#### url redirect requests for forum.com to www.forum.com
$HTTP["host"] =~ "^(forum.com)$" {
 url.redirect = ( "/(.*)" => "http://www.%1/$1")
}
Hello, Welcome to MyBB Indonesia to get local support
My 'Simple' Unique Plugin here Smile
Reply
#8
This user has been denied support. This user has been denied support.
If you want to get rid of the & sign at the end the number of rewrite rules will double, since for some reason lighttpd does not have an equivalent of QSA (or I just didn't find it), so you have to match the stuff after ? if present and manually append it.

That's what the (\?(.*)|) does currently, otherwise you'd have to make every rule twice, once with \?(.*) at the end.

I haven't found any issues due to the extra & though.
Reply
#9
This user has been denied support. This user has been denied support.
I already added your code in etc/lighttpd/lighttpd.conf but my web's getting error.
Is there any code that i should put code in .htaccess for lighttpd?
Reply
#10
This user has been denied support. This user has been denied support.
lighttpd does not use .htaccess (that's an Apache thing), so no, you shouldn't

See the troubleshooting section in the first post here, if that doesn't help you, I can't help you either.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)