Welcome Guest, Not a member yet? Register   Sign In
Custom Routing for SEO friendly URLs
#1

I am having a routing problem that i don't understand , i'm following whats on the documentation, perhaps im not fully understanding how these routes work, 
here is the issue,  i have an articles Controller which makes use of view_by_slug method, this just grabs a field from the database that instead of having : http://localhost/kewlcms/articles/view/1  in the URLs
i have this:
http://localhost/kewlcms/articles/view_b...st-article
http://localhost/kewlcms/articles/view_b...nd-article
..
.


This is the snippet i have on the home page that creates a list of the most recent posts, as you can see it uses  view_by_slug/<?php echo $article->slug; ?>

on home.php

PHP Code:
      <ul class="row marketing">
        <?php foreach ( $articles as $article ) : ?>
          <li><h4><?php echo $article->title ?></h4>
              <?php echo word_limiter($article->body20 ) ; ?>
              <p><a href="<?php echo base_url(); ?>articles/view_by_slug/<?php echo $article->slug?>">Read More</a></p>
          </li>
        <?php endforeach; ?>
      </ul> 


But i would like to change these URLs:
http://localhost/kewlcms/articles/view_b...st-article
instead of articles/view_by_slug/first-article  i would like to change it to :
http://localhost/kewlcms/articles/first-article      or
http://localhost/kewlcms/blog/first-article


This is what i have  on routes.php, i am including the 2 lines which are the ones i tried so far but  im getting 404 not found errors   Confused


PHP Code:
$route['articles/view_by_slug/(:any)'] =  'articles/$1' ;

$route['articles/(:any)'] =  'articles/view_by_slug/$1' 
Reply
#2

Is kewlcms your controller, or your install dir?
Reply
#3

(11-01-2015, 09:18 PM)skunkbad Wrote: Is kewlcms your controller, or your install dir?

It's the install dir, i have several subfolders under localhost
Reply
#4

Remove line $route['articles/view_by_slug/(:any)'] ='articles/$1':
Keep calm.
Reply
#5

Did you try using _remap()? http://www.codeigniter.com/user_guide/ge...thod-calls
You can redirect every request to index() so that will serve another method.
Reply
#6

(11-02-2015, 12:16 AM)arma7x Wrote: Remove line $route['articles/view_by_slug/(:any)'] ='articles/$1':

That didn't work,  don't  know why 
i tried what the documentation says but still can't get it to work properly
Reply
#7

I think the problem is your URI http://localhost/kewlcms/articles/view_b...st-article. 'kewlcms' is always the first segment of your URI. Fire up your apps using PHP built-in webserver with option -t which is your document root, in your case, kewlcms directory.
Keep calm.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB