0

Hi everyone, I am looking for someone to help me with a htaccess file / rewrite rule I am working with.

At the moment, my url is website/profile?id=12345678
now before I add the htaccess file, the webpage gets the id from the url and searches the database and retrieves the users data.

When I add the htaccess file - my url is website/user-name - Where user name is a field in my database
The webpage does not retrieve any user information as the get option is not valid.

What variable can I use to retrieve the users information.

here is the htaccess file. Hope someone can help me out on this as its driving me crazy.

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /profile.php?id=$1 [NC,L]

Here is the code I have been using to retrieve the user information using profile.php?id=12345678

    function validate_id($variable) {
        return is_numeric($variable);
    }
    // Get the id from the url
    if ( isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id']) ) {
        // ok it is set, not empty, and a number, get it;
        $id = trim($_GET['id']);
    }

    // use the id and search the database for user info

    $results = $Db->query('SELECT * FROM table');
    $Db->where('ref', $id);
    $results = $Db->get('table');

        if($results > 0){   
        //loop through result
        foreach($results as $row);  

Thanks in advance everyone

3
Contributors
5
Replies
25
Views
3 Years
Discussion Span
Last Post by matrixdevuk
0

use this:

RewriteEngine On
RewriteRule ^http\://website/user-name([^/]*)$ /profile?id=$1 [L]
0

use this:

You forgot QSA! Dat QSA is important!
Use this:

RewriteEngine On
RewriteRule ^http\://website/user-name([^/]*)$ /profile?id=$1 [QSA,L]
0

Hi, thanks to everyone who has replied, But when I add

RewriteEngine On
RewriteRule ^http\://website/user-name([^/]*)$ /profile?id=$1 [QSA,L]

I get a 404 error message... And yes I am changing the website to the correct website address.

0

Hi, thanks to everyone who has replied, But when I add

RewriteEngine On
RewriteRule ^http\://website/user-name([^/]*)$ /profile?id=$1 [QSA,L]
I get a 404 error message... And yes I am changing the website to the correct website address.

Change website to yourdomain.com as in, if your domain is 123.com — make it 123.com.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.