Jump to content

cbox


IPB 3 IP.Board 3: Friendly URLs at last!


iBotModz_Bot

Recommended Posts

Posted

Possibly the most often requested feature we've had since the very first version of IP.Board is 'friendly URLs'.

 

Although this sounds like you'd expect your URLs to greet you with a self-empowerment phrase first thing in the morning, it really relates to making the board generated URLs a little more attractive to both humans and search engines.

 

I am being very careful to avoid the phrase "Search Engine Optimization" in this opening few paragraphs despite it being used often in the request for friendly URLs. What we've added will definitely help with SEO but it's not a complete solution and neither is it intended to be.

 

So, what do you have?

In a nutshell: friendly URLs! The process to create and manage them is far more interesting than the end result, but more on that in a moment. Lets first look at some examples of the new URLs.

 

Here's a few sample URLs from IPB 2.3.x:

To show a forum (My Test Forum):

www.board.com/forums/index.php?showforum=10

 

To show a topic (My Test Topic):

www.board.com/forums/index.php?showtopic=99

 

To show a user (Matt Mecham):

www.board.com/forums/index.php?showuser=30

 

There's nothing wrong with those URLs. They are short and concise and they spider very well, but we can do a little better to make them more attractive.

 

If you are on a Windows webserver, you can use the 'query' string method which presents URLs like this:

 

www.board.com/forums/index.php?/forum/10/my-test-forum

www.board.com/forums/index.php?/topic/99/my-test-topic

www.board.com/forums/index.php?/user/30/matt-mecham

 

If you are on an apache based web server you can make use of the 'path_info' method:

 

www.board.com/forums/index.php/forum/10/my-test-forum

www.board.com/forums/index.php/topic/99/my-test-topic

www.board.com/forums/index.php/user/30/matt-mecham

 

Even better, if you can manage your own .htaccess files, you can make use of the mod_rewrite functionality. For convenience, the mod_rewrite code is generated for you. The end result looks like this:

 

www.board.com/forums/forum/10/my-test-forum

www.board.com/forums/topic/99/my-test-topic

www.board.com/forums/user/30/matt-mecham

 

What would happen if you used accented characters like this: Mått Méçhåm? The are simply converted into their nearest non-accented 'versions'. In this example, "matt-mecham".

 

How do I use it?

The easiest way to generate a 'friendly URL' is by making use of the {parse} tag:

 

   {parse url="showtopic=99" base="public" seotitle="my-test-topic" template="showtopic"}

 

The "seotitle" parameter (and one of few concessions to the phrase Search Engine Optimization for brevity) is the ready-formatted string to use within the URL. If you want to parse the title on the fly into something a little more friendly, then you can wrap it like so:

 

   {parse url="showtopic=99" base="public" seotitle="%%My Test Topic%%" template="showtopic"}

 

The optional "template" parameter refers to which template is used to build the URL. These templates are managed in a single file in "admin/extensions/seoUrlTemplates.php". Here's an example:

 

$templates = array(
   
   # APP: MEMBERS
   'showuser'		=> array( 'out'		=> array( 'showuser=(.+?)(&|$)', 'user/$1/#{__title__}$2' ),
							 'in'		 => array( "/user/(\d+?)/", array( 'showuser', 1 ) ) ),
   
   # APP: FORUMS						
   'showforum'	 => array( 'out'		=> array( 'showforum=(.+?)(&|$)', 'forum/$1/#{__title__}$2' ),
							 'in'		 => array( "/forum/(\d+?)/"  , array( 'showforum', 1 ) ) ),
						   
   'showtopic'	 => array( 'out'		=> array( 'showtopic=(.+?)(&|$)', 'topic/$1/#{__title__}$2' ),
							 'in'		 => array( "/topic/(\d+?)/", array( 'showtopic', 1 ) ) ),
						   
   );

 

This example shows the default template code for showing users, forums and topics. The 'out' method deals with how the link is formatted while 'in' tells IP.Board how to handle the incoming links.

 

This means that if you don't like the format of the links currently, you can change them to suit your own tastes. Modification authors can also add to this file (via an interface in the ACP) to add in friendly URLs for their own applications and modules.

 

I did mention that "seotemplate" is optional - and it is. If you don't specify a template name then IP.Board will test all available templates to the URL its examining to see if there's a match. Actually specifying which template to use simply speeds up the process a little.

 

Any variables not catered for in the templates is added at the end of the URL, separated by an underscore like so:

 

www.board.com/forums/topic/99/my-test-topic/_/view/getNewPost

 

This makes for a convenient way to transport data without having to add all the possible permutations in the template file.

 

We hope that the inclusion of this popular request will go some way into helping your overall SEO approach as well as making common links look altogether more pleasant!

 

View the full article

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...