Jump to content


Welcome to IPS!

Feel free to browse our community to get a feel for how our community software operates. Post in the pre-sales forum with any questions you have before purchasing or use the Test Posting forum to post a few messages yourself! You can also get a free demo to try the IPS Community Suite yourself.

Already an active IPS client?

Login with the same email address and password you use for the client area to access client-only areas.





Photo - - - - -

IP.Board 3: Friendly URLs at last!

Posted by Matt, 18 September 2008 · 546 views


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:

CODE
   {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:

CODE
   {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:

CODE
$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!




Thank you!

Is it possible to change the rewrite rules to reflect the current rewrite rules if people have communityseo ? original.gif
Interesting That'll be very helpful for a lot of people.
Lindsey, you can indeed.
Awsome!
QUOTE
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".

Very good. It's much more better solution than "wikipedia conversion":
CODE
M%C3%A5tt_M%C3%A9%C3%A7h%C3%A5m

biggrin.gif
lol yeah, wikipedia conversion sucks pretty hard. i had a problem with that... ufff... getlost.gif

Now on topic, great news, hope you guys will get some seo thingy's into IPB3. original.gif But i guess community seo is there... biggrin.gif
May I ask what would happen if someone had matt-mecham, and therefore it couldn't convert to that. In a few of my components, if the users name is accented, I just convert the friendly URL to their ID instead. So your accented name would simply become user/1/ instead of user/conversioncodes.

So yeah, what would happen if someone had the name it tries to convert it to, would it fall back as a last resort onto the user id?
QUOTE (Alεx @ Sep 18 2008, 12:10 PM)
May I ask what would happen if someone had matt-mecham, and therefore it couldn't convert to that. In a few of my components, if the users name is accented, I just convert the friendly URL to their ID instead. So your accented name would simply become user/1/ instead of user/conversioncodes.

So yeah, what would happen if someone had the name it tries to convert it to, would it fall back as a last resort onto the user id?


I may be wrong, but I think that part of the string is just for vanity. IPB would use the user ID anyway, so it would find the correct member even if the matt-mecham bit was shared by someone else.
But then surely visiting the URL in your browser could end up at either 'matt'? By visiting I mean links such as bookmarks or manually inserting the URL
Sounds cool and thanks for adding it.
I was thinking about getting the communityseo for this reason not sure if I still need to but it sounds like I will not need to.
The id is always inserted in the url, so the name or descriptive part has to meaning on the actual results. You could put "blah-blah-blah" and it would still come up with the same profile.

A question I have is: With the path info and windows server methods it seems like it takes a string and breaks up the values.. When you do mod_rewrite, are you falling back on GET again? Or have you completely abandoned the use of traditional query strings?

Also with adding the additional values that are not supported with this URL:

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

Why couldn't you do something like this:

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

Have the "vanity" part always be last. Is there a way to do that? The "/_/" part just seems a little odd. Or even:

ww.board.com/forums/topic/99/my-test-topic?view=getNewPost

As far as the windows servers, what about ORIG_PATH_INFO? REQUEST_URI is not set by IIS, but you can simulate it like this:

$_SERVER['REQUEST_URI'] = $_SERVER['ORIG_PATH_INFO'] . (isset($_SERVER['argv'][0]) && $_SERVER['argv'][0] != '' ? '?' . $_SERVER['argv'][0] : '');

That way you could make this:

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

Like this:

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

To be more consistent with apache (without the mod rewrite).

Also, there are some "mod_rewrite" solutions from IIS (not free). Would we be able to take advantage of these in the same way as apache?
Sorry, didn't actually see the URL was passed with the member name, blonde moment laughing.gif
Matt: Have you seen the Django urlconf system? It's such an elegant way of configuring URLs like this.

http://docs.djangoproject.com/en/dev/topics/http/urls/
Luke: There are obviously many ways we can do this. The way we've chosen is the simplest and (arguably) most efficient. We will test more extensively on a Windows server during the beta process and fine-tune the system to make it a little more accessible for Windows users.

The system sits on top of the usual query string method, so we've not done away with that. In fact, there are many areas where query strings are still used (and it's OK to do that...)
Great work.

Two questions:

- This will work on Lighttpd by default ?
- What about non-Latin characters, like for example Arabic letters ?
Absolutely Fantastic News, this will certainly aid in SERP without jeopdising performance issues with other 3rd party IPB seo modules great. Cheers!

Quick question, I know everything is pretty much possible on the internet - but I wonder if it is easy to achieve the following .(e.g. a few mod_rewrite rules/IPB Template tweaks - with IPS staff help eventually original.gif )

Making the /forum/ & /topic/ - titles actually say the topic title rather than topic e.g. www.boardname.com/forum/feedback/1023/i_need_feedback/ - as you can see /topic/ is replaced with /feedback/

How hard would that be to achieve please? or even.

www.boardname.com/forum/feedback/i_need_feedback_1023/

Does that make sense?
I assume that this will work on Windows servers that have Apache in place of IIS?

That is the only question I have. Great work.
Yeah, will we be able to create a custom URL structure for our friendly URLs?
I too want to know if this will work on Lighttpd.
Good! This is fine! biggrin.gif

February 2012

S M T W T F S
   1234
56789 10 11
12131415161718
19202122232425
26272829   

Latest Visitors

Search My Blog