Jump to content

.htaccess rewrite knowledgebase to xyz and trim + redirect extension .php or .html w/ trailing slash


Recommended Posts

May you please offer wisdom to help me achieve my desired URL for knowledgebase?

 

  • rename knowledgebase to kb
  • rearrange, so {$kbarticle.urlfriendlytitle} appears before {$kbarticle.id}
  • hide / remove / trim and or redirect extensions
  • *trailing slash
  • *force lowercase

* = extra fancy, but still, highly desirable

 

original / stock

http://domain.com/knowledgebase/1/Test.html

 

new (what I currently have with code below)

http://domain.com/kb/Test-1.html

* rearrange and rename knowledge to kb

 

desire

http://domain.com/kb/test-1

*force lowercase, remove extension and rearrange and rename

 

Here is my current code .htaccess:

 

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

 

Here is the original stock .htaccess on fresh WHMCS install:

 

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

 

I've already fired up some template files, like these:

 

  • knowledgebasecat.tpl

  • knowledgebasearticle.tpl

  • knowledgebase.tpl

After I launched up the file, I didn't have to customize that much, and I just cut / paste some code, for example:

 

stock code line #34
<a href="{if $seofriendlyurls}{$WEB_ROOT}/[u]knowledgebase/{$kbcat.id}/{$kbcat.urlfriendlyname}[/u]{else}knowledgebase.php?action=displaycat&catid={$kbcat.id}{/if}">

new code
<a href="{if $seofriendlyurls}{$WEB_ROOT}/[u]kb/{$kbcat.urlfriendlyname}-{$kbcat.id}[/u]{else}knowledgebase.php?action=displaycat&catid={$kbcat.id}{/if}">

 

---

 

sources that helped me out, but didn't get me 100% desired results:

#1 = http://stackoverflow.com/questions/9608366/remove-index-php-from-url-with-htaccess/9619319?noredirect=1#comment64671812_9619319

#2 = https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

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.

×
×
  • 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