Welcome Guest, Not a member yet? Register   Sign In
url friendly, redirect users to other users profile by usename
#1

Hello everyone 
is it possible in codeigniter to redirect users by username
in my site when users are logged in the url is like this: http://localhost/friendmiiDemo/posts when they are on their profiles the url is like this: 
http://localhost/friendmiiDemo/profile?u=abelo3088.

i want when users type other username on url like this: http://localhost/friendmiiDemo/abelo3088 be redirected to this users profile, so inside profile view i putted .htaccess file with this code:[url=http://localhost/friendmiiDemo/posts][/url]

Code:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile?u=$1

but it just wont work i don't know if is codeigniter or htccess.
if you can help or there is any other way i could do this please help
Thanks in advance.
Reply
#2

You can replace http://localhost/friendmiiDemo/profile?u=abelo3088 by http://localhost/friendmiiDemo/profile/abelo3088 by passing the username as a parameter to your method like this:

PHP Code:
<?php
class ProfileController extends CI_Controller
{
    public function profile ($username NULL)
    {
        if ( ! empty($username))
            // Display user's profile
        else
            // Show error or redirect somewhere else...
    }

CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB