Powered by MediaWiki
Personal tools

Appearance of my permalinks

From b2evolution manual

Jump to: navigation, search

The default permalinks in b2evolution look something like:
http://www.yoursite.com/blogs/index.php?title=post_title&c=1&tb=1&pb=1&more=1

You can change this behavior to something cleaner by going to the backoffice under the Blog Settings > URLs tab. There you can choose different link formats. For example:
http://www.yoursite.com/blogs/index.php/2003/05/20/post_title

On the Settings|General tab you can also set different "Permalink type" options which determine whether your links are referenced by their database ID or by the title.

Also, by installing b2evolution at the root of your website -- without using a blogs folder -- your permalinks would show like this:
http://www.yoursite.com/index.php/2003/05/20/post_title

Contents

[edit] Going further

Here's how to get rid of index.php and make your urls look more like this:
http://www.yoursite.com/2003/05/20/post_title

After you've set up your webserver by following one of the instructions below, go to your blog settings > URLs and select "Default blog on index.php" for example.

[edit] Apache webserver

Most probably you're using the Apache webserver, so try editing the .htaccess file at the root of your site and add the following lines (this requires mod_rewrite to be enabled):

RewriteEngine On

# The next line isn't always needed, but try uncommenting (removing the hash
# sign in front of the line) and setting it to the path to your "blogs" folder.
# If your URL is e. g. http://example.com/blogs, then set this to /blogs/. If
# your URL is http://example.com, set this to /.
#RewriteBase /blogs/

# Redirect anything that's not an existing directory or file to index.php:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^  index.php

[edit] lighttpd webserver

If you're using the lighttpd webserver instead, a little bit more work is required. As of 2009-02-03, the author of this article uses lighttpd 1.4.13 on Debian Etch.

You need mod_magnet, so install it with apt-get or aptitude (the package is named lighttpd-mod-magnet) and enable the module as described here.

Then save the following lua script somewhere on your server and modify the variable "prefix" (look for it after the "Main script" comment), if needed:

-- Original source: http://www.final-network.de/lighttpd-rewriterule

--[[ This function splits a string by a delimiter and returns the parts
     as a table. ]]--
function string:split( delimiter )
    local result = { }
    local from   = 1
    local delim_from, delim_to = self:find( delimiter )

    while delim_from do
        table.insert( result, self:sub( from, delim_from - 1 ) )
        from = delim_to + 1
        delim_from, delim_to = self:find( delimiter, from )
    end

    table.insert( result, self:sub( from ) )
    return result
end

-- ** Main script ** --
if ( not lighty.stat( lighty.env['physical.path'] ) ) then
    --[[ Relative path to the application's root dir, without a trailing
         slash. If the path is simply /, set this to an empty string. ]]--
    local prefix = '/blogs'
    local index_file = '/index.php'
    
    local path = ''
    local last_found = ''

    -- Detect the part of the path which points to a existing file:
    for key,part in ipairs( ( lighty.env['physical.path']:sub( 2 ) ):split( '/' ) ) do
        path = path .. '/' .. part
        if ( not lighty.stat( path ) ) then
            break
        end

        last_found = path
    end

    -- Is the detected path the same as the path to the application's root dir?
    if ( last_found == lighty.env['physical.doc-root'] .. prefix ) then
        -- Yes! Rewrite the request to the index file:
        lighty.env['uri.path'] = prefix .. index_file
        lighty.env['physical.rel-path'] = lighty.env['uri.path']
        lighty.env['physical.path'] = lighty.env['physical.doc-root'] .. lighty.env['physical.rel-path']
    end
end

This script only works properly if your doc root does not end with a slash. Add the following line to your configuration file, modifying the path to point to the Lua script you just saved:

magnet.attract-physical-path-to = ( "/var/www/b2evo_rewrite.lua" )

Now restart your webserver and pray that you now can use clean URLs. ;-)

[edit] Nginx webserver

You must open your nginx.conf or virtual.conf file and wherever you define the location for root, it should look something like below. Take note to replace the root path with the path to your installation. (not sure about subfolders but i'm sure it works too)

location / {
                        try_files $uri $uri/ /index.php?q=$uri&$args;
                        root   /www/vhosts/domain1.com/htdocs;  #absolute path to installation of b2evo
                        index  index.php index.html;
 # this serves static files that exist without running other rewrite tests
        if (-f $request_filename) {
            expires 30d;
            break;
        }

        # this sends all non-existing file or directory requests to index.php
        if (!-e $request_filename) {
            rewrite ^(.+)$ /index.php?q=$1 last;
        }

                        }

Most likely you will also want to use fastcgi too. You block should look something like this. (please refer to the nginx documentation to setup your fastcgi spawned processes and port binding)


location ~ \.php$ {
            root           htdocs;
            fastcgi_pass   127.0.0.1:9130;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www/vhosts/domain1.com/htdocs$fastcgi_script_name; #place absolute path from above before $fastcgi_scripts
            include        fastcgi_params;
        }

Restart your web server and you should now have clean urls in the form of:(or something like that)

http://domain1.com/2008/09/post-title

One last note: Make sure that any links that end in a slash (/) are eliminated from your installation unless it's actually a directory. If your url is http://domain1.com/htsrv/getfile.php/ it will think that getfile.php is a directory and send the entire path (with the slash) back to the b2evo core so when the file is called it will still have the / and the b2evo core will interpret the link wrong.

[edit] _ vs -

With b2evolution 2.0, underscores are changed into dashes/hyphens. The permalink would look like this:
http://www.yoursite.com/2003/05/20/post-title