Appearance of my permalinks
From B2evolution
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. The author of this article is using lighttpd 1.4.13 running 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 probably if your doc root isn't ending 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 you can use clean URLs. ;-)
[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

