Hi,
I have seen this somewhere, but I've lost the link to it.
My website has users who have filled out their personal particulars for display when others search for them. Picture something like Facebook, there is a public viewable profile page, displaying only the information which each member chooses to show to friends/non-friends, formatted nicely with a photo, personal details etc.
How can I make a link for them such that their profile can be accessed with such an url:
http://mydomain.com/2314
where 2314 is their unique member id.
so anyone may type that and arrive at a standard page, formatted with personal details, photos, of member 2314
*EDIT* What I have right now is something like http://mydomain.com/view_profile?memberid=2314 which allows my script to search for the user to display. How do I remove the need for passing the variable memberid?
Thanks!
How can I achieve something like this
Moderator: General Moderators
Re: How can I achieve something like this
Use .htaccess to redirect all traffic to a single controller page which handles the requests.
Re: How can I achieve something like this
Thanks Celauran,
.htaccess was something new for me, I bumped around a little and was able to get something simple like this working, to redirect all
http://www.mydomain.com
to just
mydomain.com
with
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R,L]
However, although it works, I'm not entirely sure why it did work
Can you shed some light on what ^(.*)$ is trying to match? I know regex, so ^ is beginning of line, $ matches end, .* matches pretty much anything stringed together, the $1 is what those () grabs i.e. what was matched with .* But what is it that I'm /expecting/ to match in this context though? I'm thinking its suppose to grab anything that comes after the regex pattern I defined in RewriteCond? Like in this case, anything that comes after "www.mydomain.com", so for an url like "www.mydomain.com/register.php", my $1 would be "register.php"?
Also, what is the purpose of the HTTP_HOST variable? (I know there are lots more out there, I was actually playing around with QUERY_STRING to solve my original question - trying to match the variables, but not knowing the exact effect of what specifying it does, I pretty much hit a wall)
So the variable string proves much harder to figure out for me.
If the view profile page I'm using is at
mydomain.com/view_profile.php
and the query looks like so:
mydomain.com/view_profile.php?index=1234
and I would like it to look like:
mydomain.com/1234
can you advise on what I have to use for the RewriteCond variable (I'm thinking QUERY_STRING), what I'm suppose to match with the regex, and for RewriteRule, what regex and url I should map to.
That's actually the whole answer to the question, i suppose, but I have tons more stuff to map, a complete example would help ALOT, there are just too many permutations of things here when I tried to do blind trial and error
Long post and lots of questions, but if I am able to understand these basics, I should be able to move on much more independently. Thanks Celauran and anyone at all who can share any insights on this.
And thanks a lot for pointing me towards the right direction thus far!
.htaccess was something new for me, I bumped around a little and was able to get something simple like this working, to redirect all
http://www.mydomain.com
to just
mydomain.com
with
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R,L]
However, although it works, I'm not entirely sure why it did work
Also, what is the purpose of the HTTP_HOST variable? (I know there are lots more out there, I was actually playing around with QUERY_STRING to solve my original question - trying to match the variables, but not knowing the exact effect of what specifying it does, I pretty much hit a wall)
So the variable string proves much harder to figure out for me.
If the view profile page I'm using is at
mydomain.com/view_profile.php
and the query looks like so:
mydomain.com/view_profile.php?index=1234
and I would like it to look like:
mydomain.com/1234
can you advise on what I have to use for the RewriteCond variable (I'm thinking QUERY_STRING), what I'm suppose to match with the regex, and for RewriteRule, what regex and url I should map to.
That's actually the whole answer to the question, i suppose, but I have tons more stuff to map, a complete example would help ALOT, there are just too many permutations of things here when I tried to do blind trial and error
Long post and lots of questions, but if I am able to understand these basics, I should be able to move on much more independently. Thanks Celauran and anyone at all who can share any insights on this.
And thanks a lot for pointing me towards the right direction thus far!
Re: How can I achieve something like this
I agree with this solution as I think this will be your best bet.Celauran wrote:Use .htaccess to redirect all traffic to a single controller page which handles the requests.
So you create a public profile directory such as www.domain.com/public/1234
I would then direct anything from public to a php handler that would take the 1234 from the link and display that users profile according to privacy settings within their account.
That way all you need is a standard redirect in your htaccess file but either way your going to need a php handler to execute the profile content according to the link.
Best wishes