|
-
Jun 17th, 2007, 05:58 PM
#1
Thread Starter
WiggleWiggle
URL's and htaccess maybe
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.
Last edited by dclamp; Jun 17th, 2007 at 06:02 PM.
Reason: Edited URLS
My usual boring signature: Something
-
Jun 18th, 2007, 12:27 AM
#2
Fanatic Member
Re: URL's and htaccess maybe
The standard way of doing something like that is using mod_rewrite http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Jun 18th, 2007, 12:43 AM
#3
Thread Starter
WiggleWiggle
Re: URL's and htaccess maybe
ok thanks, now i need help with mod_rewrite :P. i suck at regular expressions...
My usual boring signature: Something
-
Jun 18th, 2007, 12:55 AM
#4
Fanatic Member
Re: URL's and htaccess maybe
I have never used it myself, but there are lots of guides/tutorials on how to use it...
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Jun 18th, 2007, 03:58 PM
#5
Frenzied Member
Re: URL's and htaccess maybe
Hm... this is an interesting topic, anyone else provides a "help?"
-
Jun 18th, 2007, 04:22 PM
#6
Re: URL's and htaccess maybe
To redirect by user IDs or name differently, you need two rules:
Code:
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.
-
Jun 18th, 2007, 08:23 PM
#7
Thread Starter
WiggleWiggle
Re: URL's and htaccess maybe
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?
My usual boring signature: Something
-
Jun 22nd, 2007, 04:15 PM
#8
Thread Starter
WiggleWiggle
Re: URL's and htaccess maybe
this .htaccess file was used for the other script i used to use, can some one translate it for me :P
Code:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ view_profile.php?member_id=$1
My usual boring signature: Something
-
Jun 23rd, 2007, 05:04 AM
#9
Fanatic Member
Re: URL's and htaccess maybe
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
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|