views:

149

answers:

2

Hi, I would like to find a way for users to be able to type their username after my domain name to access their public profile page. For example, if you type youtube.com/username it shows that user's channel page. The resulting page is the same as youtube.com/user/username. So with my website, I have mydomain.example/users/profile.php?name=username It's a bit more complicated, with PHP and variables and subdirectories and everything... I would like that same page to display when I type mydomain.example/username I really have no idea where to start with this, but I suspect it would be something in the .htaccess file, which I do have access to. Thanks for any help!

edit: sorry this is a few days old, I've been having some other troubles and I haven't been able to test it until now. Anyway, it isn't working... Just to recap, I want mydomain.example/username to filter to mydomain.example/users/profile.php?name=username

Thanks..

edit2: I found this also on stackoverflow... link text i tried tweaking that, and what was mentioned here a few days ago... but it still won't work. Any ideas? I also keep finding pages that recommend the strategy this guy used: link text but it looks like that would cause more problems than it's worth. Any ideas?

+3  A: 
RewriteEngine on
RewriteRule ^user/(.*)$ profile.php?name=$1 [NC,B,QSA]
Robus
May want to make it `[QSA,NC]` so that existing query string items will get added.
Amber
I added B to escape the backreference and removed the leading / because he referred to htaccess (per-directory rules).
Artefacto
I admit I just changed the first RewriteRule google came up with. So yeah, thanks ^^
Robus
Shouldn't there be any kind of RewriteCond as a condition here?
RobHardgood
A: 

Please read my comment here, this should apply to you.

http://stackoverflow.com/questions/3144976/3145037#3145037

RobertPitt
That looks really complicated, and this htaccess stuff is kind of over my head, so it's gonna take me a while to comprehend all that. But it looks like you know what you're talking about. I'll read over it and give it a shot. Thanks @RobertPitt!
RobHardgood
all the htacess does is just change anything after the domain and PREpends it with a ? so that it gets passed into the script. then your 1 class just spits the whole of the url up and brings you back part 1,2,3 etc
RobertPitt
you need any help just shout.
RobertPitt