Welcome Guest, Not a member yet? Register   Sign In
Profile URLs
#1

[eluser]doubleplusgood[/eluser]
Hi there,

I know this subject has been discussed many times before about creating 'pretty' profile URLs. I have begun integrating this into my application and I think I am just about there, but something doesn't seem to be quite right and I think it may be to do with the htaccess.

First up, each user account has a 'username' field with their details in the DB. Then, in the config.php I have set a '.html' URL Suffix.

I have a profile.php controller as follows;

Code:
<?php

    class Profile extends Controller {
        
        function Profile()
        {
            parent::Controller();
            
            $this->load->model('profile_model');
        }
        
        function view()
        {
            $username = $this->uri->segment(3);
            
            if ( $username === FALSE )
            {
                redirect('profile');
            }
            
            $view_data = array();
            $view_data['profile'] = $this->profile_model->get_single_profile($username);
            
            if ( $view_data['profile'] === FALSE )
            {
                redirect('profile');
            }
            
            $view_data['view_file'] = 'profile/view';
            
            $this->load->view('layout', $view_data);
        }
    }

My profile_model.php looks like this;

Code:
<?php

    class Profile_model extends Model {
        
        function Profile_model()
        {
            parent::Model();
        }
        
        function get_single_profile($username)
        {
            $this->db->where('username', $username);
            $query = $this->db->get('users', 1);
            
            if ( $query->num_rows() == 1 )
            {
                return $query->row();
            }
            
            return FALSE;
        }
    }

My .htaccess looks like this;

Code:
<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9_-]+)$
    RewriteRule ^(.*)$ index.php/profile/view/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

So, I can view a user profile at this URL as an example;
http://localhost:8888/codeigniter-users/...anabi.html

However, I want to also view the profile at a URL like this;
http://localhost:8888/codeigniter-users/hanabi

I *thought* my .htaccess would sort this out, but can't seem to get it to work. Would someone be able to advise on what i'm missing? It's probably something obvious. :S

Thank you.
#2

[eluser]sihijau[/eluser]
did you set $config['url_suffix'] = '.html'; ?
try change to remove .html




Theme © iAndrew 2016 - Forum software by © MyBB