Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have profile pages set up so that it's blahblah.com/profile?id=6 (etc.)
How would i set it up so it's blahblah.com/daveisgreat (etc.) ?
Posted

The piece of software which usually does exactly this is called rewrite engine: http://en.wikipedia.org/wiki/Rewrite_engine[^].

Now, everything depends on what is your HTTP browser and your access to its configuration. Find out what do you have (perhaps using phpinfo, http://php.net/phpinfo[^]), read the documentation relevant to your Web hosting plan and, if you need to, talk to the customer service of your Web hosting provider.

If you your customers self-host your site, setting up a rewrite engine won't be a problem at all; just read the documentation on the HTTP browser used.

—SA
 
Share this answer
 
v2
Comments
enhzflep 16-Dec-13 0:03am    
+5. Another great answer from Encyclopaedia Kryukovia. :D
Sergey Alexandrovich Kryukov 16-Dec-13 0:55am    
Thank you very much, but it's rather Wikipedia and other well-know sources... :-)
—SA
enhzflep 16-Dec-13 1:09am    
You're welcome. Sure, not a difficult research task but it (Wikipedia) doesn't quite have the same ring to it. I'm in a jovial mood and the name just came to me. I figured you were unlikely to be offended, so thought I'd offer the broader compliment with the play on words. :)
Sergey Alexandrovich Kryukov 16-Dec-13 1:46am    
Offended? You must be joking. It's hard to offend me. I rather feel way too much flattered. :-)
—SA
enhzflep 16-Dec-13 1:48am    
Perfect! Didn't think you'd take it the wrong way.
Hi Friend,
I have a solution considering your server or webhost supports rewrite module...
# This is the .htaccess file
# You need to append these codes in your .htaccess file

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule (.*) index.php/$1 [L]


Now when you have done this, the next step is a url parsing engine... a simple example is as follow
PHP
/**
 *  A Simple URL Parsing Engine
**/
require_once CLASS_PATH.'database.php';
require_once CLASS_PATH.'generator.php';

class URIParser {
  private $uri;
  private $new_uri;
  private $raw_data;
  
  function __construct()
  {
    $uri = trim($_SERVER['REQUEST_URI'], '/');
    $this->uri = explode('/', $uri);
  }

  function parseUri()
  {
    $user = $this->uri[0];
    $db = new Database();
    $db->start();
    $db->prepare("SELECT ID FROM * WHERE username = '?'");
    $response = $db->execute(array($user));
    $db->stop();
    $id = $response[0]['ID'];
    
    $this->new_url = BASE_URL."profile.php?id=".$id;
  }

  function display()
  {
    $generator = new Generator();
    $generator->prepare($this->new_uri);
    $this->raw_data = $generator->get();

    echo $this->raw_data;
  }
}

$parse = new URIParser();

$parse->parseUri();

$parse->display();
?>


This code is an abstracted example of how this can be achieved... This is not a complete code. I hope that this code has given you some idea. By the way a very simple method though is url rewrite module but this is a cool method as you have a lot of control over how to parse the url and it is a more advanced method too.... :D

With Regards
Tushar Srivastava
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900