Personal Profile URL Help

A

Anonymous

Guest
Hi All,

Was wondering if there is another way to make personal urls for users on a site without creating a directory for all
the users.

This is an example of what i mean:
http://www.yoursite.com/username

At the momment im using the .htaccess file to point a error 404 to a php file, which from there i display the users
info, the only problem doing it this way is, that Internet Explorer 5.0 always shows there own error 404 page unless the page i create is over 512bytes. This is really annoying and dont want to use the error 404 to do this. I think there might be something that can be done using the Rewrite mod in the .htaccess but im not so sure.

If anyone has any ideas or tips please get back to me.

Thanks in Advance...
 
I dont think there is any role of mod_rewrite in your problem or it may be i could not understand your problem.

Can you please be more specific about your problem?
 
Yes mod_rewrite would be the solution.
Note: For security reasons you better start your users page in a url like: http://www.yoursite.com/user/username.
Just to prevent problems if a user creates a username like: cgi-bin :D

Ok, here goes a little example on how to handle that with mod_rewrite (.htaccess).
Store this .htaccess in your root folder (example):
Code:
RewriteEngine On
RewriteBase /

# Makes users' pages URL
# Where $1 is the username: ... /user/username
# Should work in both Apache 1.3.* and 1.2.*

# Ex: /include/users/ is the folder/user file where you'll handle the use page.
# Give a full path to that yif you get problems

RewriteRule ^user/(.*)/?$ /include/users/$1.php [L]
So let's say in you folder '/include/users/' you have:
- john.php
- mary.php
- whatever.php

Accessing http://www.yoursite.com/user/john you will sent to /include/users/john.php, but the URL http://www.yoursite.com/user/john will remain in the address bar.

Well, just an example. Also, theres a few things you can do/change depending on your needs.
 
gesf said:
Yes mod_rewrite would be the solution.
Note: For security reasons you better start your users page in a url like: http://www.yoursite.com/user/username.
Just to prevent problems if a user creates a username like: cgi-bin :D

Ok, here goes a little example on how to handle that with mod_rewrite (.htaccess).
Store this .htaccess in your root folder (example):
Code:
RewriteEngine On
RewriteBase /

# Makes users' pages URL
# Where $1 is the username: ... /user/username
# Should work in both Apache 1.3.* and 1.2.*

# Ex: /include/users/ is the folder/user file where you'll handle the use page.
# Give a full path to that yif you get problems

RewriteRule ^user/(.*)/?$ /include/users/$1.php [L]
So let's say in you folder '/include/users/' you have:
- john.php
- mary.php
- whatever.php

Accessing http://www.yoursite.com/user/john you will sent to /include/users/john.php, but the URL http://www.yoursite.com/user/john will remain in the address bar.

Well, just an example. Also, theres a few things you can do/change depending on your needs.


Awesome! Thanks alot buddy, been looking for a fix for about a week now and it was drivin me crazy, this worked like a charm, was just wondering, im totally new with the whole mod_rewrite thing, but once it works on one web browser it will work on all browsers right? Reason i ask it i just ran into the whole wierd thing IE 5.0 does with error 404 pages cause they seem to use there own error pages if the sites error 404 page isnt over 512 bytes.

Anywho, thanks again for the help it works great :D
 
Yep... once Apache recognizes the command... it will work great in all web browsers :)
 
The thing is that its done server-side and therefore not dependant of any browsers.

Yes error page problem is a standard behaviour for IE..
 
Apache and PHP are the best softwares I've ever worked till now, Too good and fun in using
 
Hey Again... :D

Was wondering another thing about the RewriteRule.

If you had a page before like for example: http://www.yoursite.com/user_profile.php?view=username

Which now doesnt exist since i last updated the site.
So in return gives a error 404. So my questions is:
Is there a way to use the RewriteRule to either redirect or use index.php?P=$1 to get the source?

What i got now is:
Code:
 RewriteRule ^user_profile\.php?view=(.*)?$ index.php?P=$1 [L]

which doesnt work.

Well any info on this would be awesome. Thanks in advance. :D
 
Back
Top