jaymc Posted September 19, 2007 Share Posted September 19, 2007 I have a profile page that knows which user to grab data for via the GET www.site.com/p.php?user=fred What I want is to use this approach www.site.com/fred In this case surely I would have to have a directory called fred and some kind of code in there to pick up that where looking for fred.. However, I know sites that use this method and Im pretty sure they dont have 300,000 member directories Is there a way around it? I have full control over appache by the way maybe a virtual host with the servername of profile.site.com?user= Not sure how I can do this, feedback would be great Quote Link to comment Share on other sites More sharing options...
ki Posted September 19, 2007 Share Posted September 19, 2007 edit your .htaccess file and use the following: RewriteEngine on RewriteRule ^([^/\.]+)/?$ p.php?user=$1 [L] Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 19, 2007 Author Share Posted September 19, 2007 THANKS !!!!! Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 19, 2007 Author Share Posted September 19, 2007 What about membername.site.com Again that would usually require a Vhost. anyway to do it via htaccess Cheers Quote Link to comment Share on other sites More sharing options...
Sorthy359 Posted September 19, 2007 Share Posted September 19, 2007 verbally when you say it out loud it sounds smoother to say site.com/fred .. also, when someone mispells a real directory name, it might say "user not found" instead of page not found. keep that in mind ..i would personally put "page not found" Quote Link to comment Share on other sites More sharing options...
ki Posted September 19, 2007 Share Posted September 19, 2007 good point sorthy thats why I did that with my 404.shtml page so you get an error like "wrong id" Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 19, 2007 Author Share Posted September 19, 2007 Anyway to go with membername.site.com rather than site.com/membername Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 19, 2007 Author Share Posted September 19, 2007 edit your .htaccess file and use the following: RewriteEngine on RewriteRule ^([^/\.]+)/?$ p.php?user=$1 [L] That works, but, any other link I go to on my page directs to p.php For instance I have www.site.com/messages Its taking them to p.php and treating it as this URL www.site.com/p.php?user=messages How did I get around that? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 19, 2007 Share Posted September 19, 2007 You probably want to do http://site.com/users/username/ so that you won't loose all your other pages. Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 19, 2007 Author Share Posted September 19, 2007 dam, is there any other way at all? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 19, 2007 Share Posted September 19, 2007 What if you have a user who signs up as "messages". How do you tell which messages page you want, their profile or the messages page? Make the users have a distinct type of url, it will be easier. Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 20, 2007 Author Share Posted September 20, 2007 I dont want to have www.site.com/users/username I want to just have www.site.com/username But, if I have a script inside of a folder called files, it thinks www.site.com/files is a username called files I dont think its going to be possible, however, im sure faceparty do it! Anyway, how about www.membername.site.com instead, how can that be achieved through rewrite rule? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 20, 2007 Share Posted September 20, 2007 don't use www Do you know see the issue that I brought up? I mean, what if you have a user called files? How do you know which they want to get to. You can do site.com/username if you make sure all of your other urls are within another directory. But otherwise there is no way to tell what is what. Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 21, 2007 Author Share Posted September 21, 2007 Its better to have members.site.com static pointing to www.site.com/users Then I can have members.jaydiocity.co.uk/username Smarter Cheers for help! Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 21, 2007 Author Share Posted September 21, 2007 Hey Ive ran into a new problem members.site.co.uk/username works fine However, some of my members names have weird characters in them, even something as simple as a fullstop is causing a problem members.site.co.uk/.my.name. I get page cannot be displayed Any ideas?! Quote Link to comment Share on other sites More sharing options...
jaymc Posted September 22, 2007 Author Share Posted September 22, 2007 Also, my new way of using a subdomain as members.site.com/username How about the original way site.com/username, but, have something that looks to see if thats an actual directory first... or if that member exists or not Just wondering how to go about that... How do myspace do it? because they have directories in there top level... Quote Link to comment Share on other sites More sharing options...
sljaxon Posted September 22, 2007 Share Posted September 22, 2007 I highly recommend reading this tutorial on mod_rewrite: http://www.easymodrewrite.com. For example, you can do exactly what you want to do with this htaccess code: RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule (.*) p.php?user=$1 [QSA,L] This essentially tells Apache and mod_rewrite to first look if the file exists. If it does not, run it through p.php. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.