Jump to content

SEO friendly knowledgebase links


jasonBV

Recommended Posts

Below are the steps I took to setup setup mod_rewrite and what files need to be modified for SEO friendly links.

 

What is a SEO friendly link? Here's an example.

Normal knowledgebase url: /knowledgebase.php?action=displayarticle&catid=1&id=1

 

Friendly URL: /knowledgebase/1/1/This_is_my_help_article.html

 

Note that if you're rewriting your links with extra directories, you will have to be careful of any relative links you have such as javascript or style includes. My regular expressions are a little rusty, so I make no guarantees that this will work 100% for everyone :) If anyone has a better way to do this feel free, but I found it to be a little difficult with only template access.

 

1) Make sure you have mod_rewrite installed and access to add .htaccess options.

 

2) Add the following to your root .htaccess file:

 

RewriteEngine On

RewriteRule ^knowledgebase/([0-9]+)/([0-9]+)/[a-z0-9_-]+\.html$ /knowledgebase.php?action=displayarticle&catid=$1&id=$2 [L,NC]

RewriteRule ^knowledgebase/([0-9]+)/([^/]*)$ /knowledgebase.php?action=displaycat&catid=$1 [L,NC]

 

3) Open your knowledgebase.tpl file and modify the article links to the following:

<a href="/knowledgebase/{$kbarticle.category}/{$kbarticle.id}/{$kbarticle.title|regex_replace:"/ /":"_"|regex_replace:"/[\?\'\.\,\!]/":""}.html">{$kbarticle.title}</a>

 

Change the knowledgebase category links to the following:

<a class="menu" href="/knowledgebase/{$kbcat.id}/{$kbcat.name|regex_replace:"/ /":"_"|regex_replace:"/[\?\'\.\,\!]/":""}">

 

4) Do the same with the knowledgebasecat.tpl and change the article links as above.

 

You can use thing for custom cart URLs, just modify the links in the TPL file and .htaccess file.

 

Here's an example of my setup: http://www.bargainvoice.com/knowledgebase.php

Link to comment
Share on other sites

  • Replies 93
  • Created
  • Last Reply

Top Posters In This Topic

If you're using the default knowledgebase templates, your article link will look like this:

 

<a href="knowledgebase.php?action=displayarticle&catid={$kbarticle.category}&id={$kbarticle.id}">{$kbarticle.title}</a>

 

Original category links look like:

<a href="knowledgebase.php?action=displaycat&catid={$kbcat.id}"><img src="images/support/folder.gif" border="0" align="middle" alt="" /> {$kbcat.name}</a>

Link to comment
Share on other sites

This is very nice solution. I hope it will get in whmcs release in next versions.

 

I made all changes as described, but I got "500 Internal Server Error". I seems it got something to to with On .htaccess File Apache. I made some google search but, i haven't found any solution on this. Any idea?

Link to comment
Share on other sites

This is very nice solution. I hope it will get in whmcs release in next versions.

 

I made all changes as described, but I got "500 Internal Server Error". I seems it got something to to with On .htaccess File Apache. I made some google search but, i haven't found any solution on this. Any idea?

 

It sounds like either mod_rewrite isn't installed or you have something wrong in the .htaccess file causing it to error. There should be an error message in your webserver logs.

Link to comment
Share on other sites

yes it would be nice if there was an option that you could turn search engine friendly URLs on or off... like you can with joomla. You'd still have to edit your .htaccess file but it would be helpful if you didn't need to edit your template files.

Link to comment
Share on other sites

Ideally it would be great if this could be taken by Matt and made part of the default release, maybe just with a configuration "ON/OFF" for SEO friendly url's at least then we dont go ahead and use this, then when it gets added to whmcs all our url's for KB articles change yet again...

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

 

We support mod_rewrite however when i add the two lines:

RewriteRule ^knowledgebase/([0-9]+)/([0-9]+)/[a-z0-9_-]+\.html$ /knowledgebase.php?action=displayarticle&catid=$1&i d=$2 [L,NC]

RewriteRule ^knowledgebase/([0-9]+)/([^/]*)$ /knowledgebase.php?action=displaycat&catid=$1 [L,NC]

 

we also get the 500 error.

Link to comment
Share on other sites

You will want to check your web server error logs to see what error is being thrown.

Great tip! I do wish this was in the base system so we wouldn't have to use .htaccess.

 

Anyway,

RewriteRule ^knowledgebase/([0-9]+)/([0-9]+)/[a-z0-9_-]+\.html$ /knowledgebase.php?action=displayarticle&catid=$1&i d=$2 [L,NC]

Has a space between "&i" and "d=$2" near the end of the line. You are probably getting 500 errors (specifically in your error logs... htaccess: RewriteRule: bad flag delimiters).

 

Remove the space and you should be okay.

RewriteRule ^knowledgebase/([0-9]+)/([0-9]+)/[a-z0-9_-]+\.html$ /knowledgebase.p

hp?action=displayarticle&catid=$1&id=$2 [L,NC]

Thanks again for the tip, its working great!

Link to comment
Share on other sites

  • 3 weeks later...
All the images and CSS are broken, the page open, dont have 500 server error, but the css and the images do not apers.

 

 

try to use underscore instead of slash: "_" instead of "/" like this:

 

RewriteRule ^knowledgebase_([0-9]+)_([0-9]+)_[a-z0-9_-]+\.html$ /knowledgebase.p

hp?action=displayarticle&catid=$1&id=$2 [L,NC]

 

 

try this solution

Link to comment
Share on other sites

try to use underscore instead of slash: "_" instead of "/" like this:

 

RewriteRule ^knowledgebase_([0-9]+)_([0-9]+)_[a-z0-9_-]+\.html$ /knowledgebase.p

hp?action=displayarticle&catid=$1&id=$2 [L,NC]

 

 

try this solution

 

Works perfectly!! Now I need solve the problem of replacement of accents by letter without the accent (eg "é" by "e" and, "á" by "a").

 

Thanks!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated