Jump to content

SEO friendly knowledgebase links


jasonBV

Recommended Posts

I figured it out, you have to change the / not only on the htaccess, but the tpl files as well.

 

The reason the css and images are not working is because the rewrite makes the file look like its coming from a folder, and since that folder is not the root, it cant load the template files.

Link to comment
Share on other sites

  • Replies 93
  • Created
  • Last Reply

Top Posters In This Topic

[L,NC] = Last rule (stop matching additional rules), No Case (case insensitive)

 

id=$2 = Sets the ID to the second parameter matched by the rule. This in effect passes the value matched by $2 as $_GET[id] to php.

 

Hope that helps.

Link to comment
Share on other sites

Nothing..

now i ask to a "php-builder"...(

 

my whmcs is into /panel

 

therefore the real link is http://www.domainxx.tld/panel/knowledgebase.php

 

i put into .htaccess (under puclic_html/ )

this code (i try with / , with _ , without /panel, etw)

 

RewriteEngine On

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

 

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

 

 

into knowledgebase.tpl and knowledgebasecat.tpl i put

 

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

<img src="images/support/folder.gif" border="0" align="middle" alt="" /> {$kbcat.name}</a></strong> ({$kbcat.numarticles})<br />

 

and

 

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

 

 

but not fine:(

Link to comment
Share on other sites

  • 2 weeks later...

Hey all.

 

Has anyone managed to get the relative links problem working. At the moment, our seo friendly URLS look something like this

 

/knowledgebase/7/53/Attachments.html

 

does anyone know if it would be possible to change the same thing to something like

 

/knowledgebase-7-53-Attachments.html

 

which would thus fix the relative links problem and maintain the data, and keep them fairly friendly.

 

Ben

Link to comment
Share on other sites

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

 

Hi!

 

I tried the same way that was specified,ok the .htaccess file didnt give any error as i have changed id spacing thing and thats solved, but now my problem is as you specified i have two tpl files knowledgebase and knowledgebasecat, you are telling me to replace the existing lines with your lines, but i dont find the existing lines anywhere, i am using latest version whmcs3.6.2, can you please guide me the process?

Link to comment
Share on other sites

404 errors, somethings wrong either in your .htaccess expressions or in the links. look at the web address you're getting to in order to troubleshoot.

 

for those getting the stuff to work without styling in the articles, adding the following to the head code of their header template file setting the base will fix it. since all the whmcs stuff shows as being from the same folder, structurewise, this doesn't break anything.

 

 
<base href="http://whmcs.domain.com/" />

 

whatever your domain is, of course. :) call this BEFORE any style sheet or javascripts, etc. to maintain the path.

Link to comment
Share on other sites

404 errors, somethings wrong either in your .htaccess expressions or in the links. look at the web address you're getting to in order to troubleshoot.

 

for those getting the stuff to work without styling in the articles, adding the following to the head code of their header template file setting the base will fix it. since all the whmcs stuff shows as being from the same folder, structurewise, this doesn't break anything.

 

 
<base href="http://whmcs.domain.com/" />

 

whatever your domain is, of course. :) call this BEFORE any style sheet or javascripts, etc. to maintain the path.

 

 

This do not break the http and https switch?

Link to comment
Share on other sites

This do not break the http and https switch?

 

nope, this worked fine for me. if you think about it, all it's doing is making the links for seo-friendly page based out the main whmcs folder instead of appearing to be in imaginary folders you're setting up with the new links. because the other pages are already showing as being in the main whmcs folder, it's no effective change on most pages.

Link to comment
Share on other sites

sure....after i did add the base url in the header template if you login as a user through the admin panel, then click in the My hosting packages ---> View details. This keep me loading the Home page instead to show me the hoting package details.

Same issue with My domains --> View details.

 

Just removing the base tag from the header template is correcting this so thats the cause.

Link to comment
Share on other sites

If you want to use the base href thing but have it handle both secure and non-secure URLs, here's a snippet of code that should work:

 

<?php
 $site = "www.domain.com/"; // replace with your site
 $prefix = ($_SERVER['SERVER_PORT'] == '80') ? 'http://' : 'https://';
 echo '<base href="'.$prefix.$site.'" />';
?>

 

Put that in a file named basehref.php, put it in your WHMCS root, and then in your header.tpl template add:

 

{include_php file="basehref.php"}

Link to comment
Share on other sites

Thanx Troy,

 

Yes that should work, i was testing another way to avoid have that file in my root.

Just using this code in the header.tpl do the trick:

 

{php}
$http_mode = (!empty($_SERVER['HTTPS'])) ? 'https://' : 'http://';
$my_url = $http_mode . $_SERVER['HTTP_HOST'];
echo '<base href=/"$my_url/" />';
{/php}

Link to comment
Share on other sites

For those of you having issues with your knowledgebase relative links etc and tried the above but then it messes up other pages (SSL pages etc) you can do this instead:

 

in header.tpl add between <head> and </head>:

 

{if $pagetitle eq "Knowledgebase"}
<base href="http://www.domain/WHMCS INSTALL PATH" />
{/if}

 

this will then only force the base href on the knowledgebase page!

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