Click to See Complete Forum and Search --> : URL's and htaccess maybe
dclamp
Jun 17th, 2007, 06:58 PM
I want to have a url like "http://www.mysite.com/mypage". the "mypage" is going to be different for every user. It may also be a number.
My question, how do i make it so it will do that, and to check if it is a name or a number. ex:
URL:: mysite.com/dclamp
Actual Page: mysite.com/view_profile.php?id=dclamp
URL:: mysite.com/13
Actual Page: mysite.com/view_profile.php?id=13
EDIT:
i dont want to redirect it.
McCain
Jun 18th, 2007, 01:27 AM
The standard way of doing something like that is using mod_rewrite http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
dclamp
Jun 18th, 2007, 01:43 AM
ok thanks, now i need help with mod_rewrite :P. i suck at regular expressions...
McCain
Jun 18th, 2007, 01:55 AM
I have never used it myself, but there are lots of guides/tutorials on how to use it...
vbbit
Jun 18th, 2007, 04:58 PM
Hm... this is an interesting topic, anyone else provides a "help?"
penagate
Jun 18th, 2007, 05:22 PM
To redirect by user IDs or name differently, you need two rules:
RewriteEngine On
RewriteRule ^([0-9]+)$ files/view_profile.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z_]+)$ files/view_profile.php?name=$1
Note that the second of those will only allow user names containing characters that are alphanumeric or underscores. You may want to add additional characters. However, don't add a dot (\.) as that will cause rewriting to take place on URIs for things like images and CSS/script files.
dclamp
Jun 18th, 2007, 09:23 PM
well i think i will have it so the var id will be for both name and id number, then i will do the checking in php,
what do i need to change in your code?
dclamp
Jun 22nd, 2007, 05:15 PM
this .htaccess file was used for the other script i used to use, can some one translate it for me :P
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ view_profile.php?member_id=$1
McCain
Jun 23rd, 2007, 06:04 AM
In this line: RewriteRule ^(.*)$ view_profile.php?member_id=$1
^ matches the start of the string. $ matches the end of the string and (.*) matches and captures anything in between. The $1 at the end of the string gets replaced with whatever (.*) captured
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.