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

Recommended Answers

All 5 Replies

Where you have NC,L... put:
QSA,L

use this:

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

use this:

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

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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.