Facebook's profile & URL scheme

This might involve PHP or Apache’s .htaccess. I would like to understand how Facebook does their URL scheme. Like when you have a profile such as

/spaceshiptrooper

And then you put periods in that string

/space.ship.trooper

It gets treated like

/spaceshiptrooper

How is this possible? Do they just strip out the periods and the select and compare it to an sql string? What about if the profile has random periods in it and the requested string doesn’t? How do they treat it the same?

Currently, my application only allows alphanumeric and underscores. I want to allow underscores and periods. So mine basically is already set up to allow both via .htaccess already, however, I can’t seem to understand the concept and how you would do that to get the right profile using PHP.

If it was done in .htaccess would the address bar not still be showing the dots?

Well. The application is using MVC so all request get sent to the same controller file. So the main problem is going to happen in PHP. Because if the profile doesn’t exit, it’ll already load up the 404 error page. Everything is working. Just that I don’t know how to go about it since if you try Facebook’s URL scheme, no matter where you place the period, you will be shown the same profile. This only does not work with certain profiles because they had their profile before this change. Basically, what I was think was to strip out all the periods from the requested profile. Then strip out all the periods from a database call and then compare them. If they are the same, they should be the same profile. However, I feel there’s a down side to this. So I would like to know how Facebook did theirs.

Because if you think about it, users can’t have the same usernames anyways. So having the same username with space.ship.trooper would be the same as spaceshiptrooper once you do the comparison.

I wonder if the periods are being stripped out or if they are getting replaced with a wildcard.

i.e.

is space.ship.trooper getting changed to spaceshiptrooper or space%ship%trooper?

Does spaces.iptrooper return spaceshiptrooper?

Dots are just stripped out

s.p.a.c.e.s.h.i.p.t.r.o.u.p.e.r will give spaceshiptrouper

1 Like

IMHO then it’s more likely not htaccess doing the magic, but sanitizing the GET before running the query.

i.e. any characters not allowed would likewise be removed.

2 Likes

I see. Thanks both of you. I think I know how it works now.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.