b2evolution b2evolution

  • Sign in
  • Sign up
  • About
  • Downloads
  • Hosting
  • Docs
  • Support
  • Sign in
  • Sign up
  • Manuals Home
  • Latest Updates
 
  1. b2evolution CMS User Manual
  2. Archives
  3. How to Change the Appearance of my Permalinks

How to Change the Appearance of my Permalinks

This page refers to an older version of b2evolution.

The default Permalink in b2evolution look something like:
http://www.yoursite.com/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/index.php/2003/05/20/post_title

On the Collection URL settings you can also set different "Permalink type" options which determine whether your links are referenced by their database ID or by the title.

Going farther

Here’s how to get rid of index.php and make your urls look more like this:<br />
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.

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

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. ;-)

Nginx webserver

Open your nginx.conf or virtual.conf file, it should look something like below. Take note to replace the root path with the path to your installation. ‘'’Don’t move”’ "locations" around, they need to stay on their places, it’s important!


server {
	listen	80;
	server_name www.domain.com domain.com;
	
	root	/home/www/domain/public_html;  #absolute path to installation of b2evo
	index	index.php index.html index.htm;

	# Never cache admin.php
	location ^~ /admin.php {
		include			fastcgi.inc;
		fastcgi_param		SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	}
	
	# Cache everything for 7 days. No PHP in "rsc" directory!!!
	location ^~ /rsc/ {
		access_log off;
		expires 7d;
	}
	
	# Deny access to sensitive stuff
	location ~ ^/(cache|conf|cron|inc|locales)/ {
		return 404;
	}
	
	# Never cache PHP scripts in these directories
	location ~ ^/(htsrv|xmlsrv|plugins)/(.+\.php)(.*)$ {
		include			fastcgi.inc;
		fastcgi_param		SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	}

	# Uncomment if you put b2evo in sub-folder (testing needed!)
	# location /blogs {
	#	if (!-e $request_filename) {
	#		rewrite ^(.+)$ /blogs/index.php?$request_uri last;
	#	}
	# }

	# Direct call to .php file
	location ~ ^(.+\.php)(.*)$ {
		# This location may be cached
		# You need to set no_cache cookie in b2evo and validate it here
		
		include			fastcgi.inc;
		fastcgi_param		SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	}
	
	location @php {
		internal;
		
		if (!-e $request_filename) {
			rewrite ^(.+)$ /index.php?$request_uri last;
		}
		
		# This location may be cached
		# You need to set no_cache cookie in b2evo and validate it here
		
		fastcgi_index		index.php;
		include			fastcgi.inc;
		fastcgi_param		SCRIPT_FILENAME  $document_root/index.php;
	}

	# See if we can get a static file, transfer request to @php location if file not found
	location / {
		try_files $uri $uri/ $uri/index.php @php;
		access_log off;
		expires 7d;
	}

	# Deny access to sensitive stuff
	location ~ /\.ht { deny all; }
	location ~ /error_log$ { deny all; }
	location ~ /core$ { deny all; }
	location /_backup { deny all; }
	location = /robots.txt { log_not_found  off; }
	location = /favicon.ico { log_not_found  off; }
}

Your fastcgi.inc file should look something like this. (please refer to the nginx documentation to setup your fastcgi spawned processes and port binding)


fastcgi_pass			127.0.0.1:9000;   #unix:/tmp/php-fpm.sock;
fastcgi_buffers			256 16k;
fastcgi_buffer_size		32k;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

Restart your web server and you should now have clean urls in the form of (or something like that)
http://www.domain.com/2008/09/post-title

Note that this config also covers links like this. No changes needed
/htsrv/getfile.php/image.png?foo=bar

_ vs -

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

Tags: obsolete
Created by fplanque • Last edit by fplanque on 2020-06-09 00:25 • •

No feedback yet

On this page

  • Going farther
  • Apache webserver
  • lighttpd webserver
  • Nginx webserver
  • _ vs -

Search the Manual

Content Hierarchy

  • b2evolution CMS User Manual
  • User's Guide
  • Installation / Upgrade
  • Front-office Reference
  • Back-office Reference
  • Developer Reference
  • Operations Reference
  • Advanced Topics
  • Glossary
  • Archives
    • Documentation Effort
    • How to call a blog from a subdirectory?
    • Converting WordPress Themes
    • Evoskin and A Template
    • Quick Upgrade Procedure
    • International Manuals
    • Known Issues
    • Online Help
    • Pretty URL
    • Pro WordPress Theme Conversion
    • Skin/Plugin XML Descriptions
    • Template Tag: Item Views
    • Version
    • How to Change the Appearance of my Permalinks
    • CVS / SourceForge
Free CMS

This online manual is powered by b2evolution CMS – A complete engine for your website.

About b2evolution

  • What is it?
  • Features
  • Getting Started
  • Screenshots
  • Online demo
  • Testimonials
  • Design philosophy
  • Free & open source
  • Terms of service

Downloads

  • Latest releases
  • Skins
  • Plugins
  • Language packs

About us

  • About us
  • Contact

Webhosting Guide

  • Web hosting blog
  • Best web hosting
  • Cheap web hosting
  • Green web hosting
  • Hosting with SSH
  • VPS hosting
  • Dedicated servers
  • Reseller hosting
  • Int'l: UK / France

Docs & Support

  • Online manual
  • Forums
  • Hire a pro !

Other

  • Adsense
  • Press room
  • Privacy policy

Stay in touch

  • GitHub
  • Twitter
  • Facebook
  • LinkedIn
  • News blog
  • RSS feed
  • Atom feed

Founded & Maintained by François Planque