The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How do I setup mydomain.co.uk/username/ folders?

Hello everyone. Hope you're all well (and hope someone can help me here!)

I'm working on a project that needs to allow people to type in mydomain.co.uk/username/ as a URL and then this will redirect them to their profile page. I'm using PHP to code the site, so a PHP related solution would be great.

My project is working around profile pages. These profile pages will have stuff on it, related to that username. I was thinking of when a user signs up, my PHP code creates a new folder on the root directory named with the username's username... Then the PHP code will copy a template profile page into this newly created directory...

Would this be a good way of doing it? It'd be nice if these profile pages were search engine friendly too...

This mod_rewrite melarky... How does this actually work then? What does it actually do? Also, will using that be search engine friendly? I kind of want these profile pages to be a page of their own (in search engine terms)...

Now apache will check any requests to see if a file or directory with that name already exists and if so load that instead. And yes, this system is very search engine friendly because as far as the search engine is concerned these are separate pages.

Is that correct right? Then on the profile.php I will have $_REQUEST['id']? To validate the ID, I need to check that it matches a username in the database yes? Is there anyother checks I need to do it?

Also, Is there any special requirements for this thing to work? Will I need to contact my hosting company to make sure it supports this type of thing?

littlejim, the $1 comes from the way apache handles mod_rewrite, it basically means the first variable. So if you had two regex's you would then have $1 and $2. Read up on it if you want, you can do amazing things with a dash of m_r.

As for the PHP page, I would normally use $_GET['id'] but request will work. Just remember to sanitise the input in case someone tries an SQL injection attack. This code should help get you started:

PHP Code:

<?php// connect to database here$username = mysql_real_escape_string($_GET['id']);// now you can perform a query to get the users data etc?>

If you add an R flag to the rule the browser will recieve a Redirect code in the header, showing that the page has moved. However this harms your search results as it's merely counted a re-direct page, not a full page in itself.