Welcome Guest, Not a member yet? Register   Sign In
seo friendly url without the controller name in the url
#1

[eluser]Unknown[/eluser]
I think I need a bit of coding help or guidance here.


If this is a shop directory I want my url to look like this :

www.example.com/shopname

i.e www.mydomain.com/abc-shop

At the moment, I've a controller called shops and the index function loads all the shops with pagination. and the controller called shopname loads the profile page for each shop.

Therefore, for a shop's profile page the url looks like this:
www.mydomain.com/shopname/shop-name

Question one: Any idea what do I need to do so I can turn the url into this www.mydomain.com/abc-shop for the profile page?

Question two:
I've noticed even with a .htaccess file and the right writerule I still need to specify controllername/index to load a page in few occasions.

If that was in every single case, I'd have thought something is missing in my .htaccess file. But it works fine in most of the cases. I.e when I load my default controller or other controller I dont have to specify controllername/index, just controllername does the job. If someone can shed some light on this as well I will be grateful.



Code:
class Shops extends Controller{
function index()
    {            
        $config['base_url'] = base_url().'shops/index';
        $config['total_rows'] = $this->db->get('shops')->num_rows();
        $config['per_page'] = 10;
        $config['num_links'] = 5;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';
        
        $this->pagination->initialize($config);
        $limit = $this->uri->segment(3);
        if(empty($limit)){
            $limit = 0;
        }
        
        $page_details['records'] = $this->shop_model->getallshop($limit,$config['per_page']);
        $this->load->vars($page_details);
        $this->load->view('main');
    }


function shopname()
    {
        $shopname    =    $this->uri->segment(3);    
        $page_details['data']    =    $this->shop_model->getdetails($shopname);
        $this->load->vars($page_details);
        $this->load->view('shopprofile');
        
    }

}
#2

[eluser]Buso[/eluser]
http://ellislab.com/codeigniter/user-gui...uting.html

http://ellislab.com/codeigniter/user-gui...llers.html
Quote:The "index" function is always loaded by default if the second segment of the URI is empty.
#3

[eluser]Flyingbeyond[/eluser]
I think you should read the router part of the user guide then you will get how to solve this problem...




Theme © iAndrew 2016 - Forum software by © MyBB