Implementing friendly URL's like Facebook has for user profiles

MisterBigglesworth

Expert Member
Joined
Aug 15, 2006
Messages
3,334
Reaction score
13
Location
/\\/ÂŻÂŻÂŻ\//\
Im trying to do the same thing on a website eg: instead of a user having "their" page show as:

http://website.com?mem_id=10245

I want it to show as:

http://website.com/memberuniqeuname

Anyone know how to do this or can send me a link? I searched Google...but am not getting a finite answer for this.

So basically I assume the PHP code would need to create this friendly URL when a member registers on the website, or is there some sort of job that needs to run in the background? :confused: I need it to "create" this friendly URL as the user registers

Im stuck :confused:
 
Last edited:
If you are using WordPress it works like a charm, url's are automatically assigned a 'nicename'
 
Thanks guys, will take a look at your replies.

It's a PHP website...all custom code.

htaccess wont work as I would have to manually add an entry each time a member registers and associate their unique ID to a unique URL. I need something on the fly as they register where I pass through parameters, for example, and it gives me back a friendly URL for "their" page.
 
Thanks guys, will take a look at your replies.

It's a PHP website...all custom code.

htaccess wont work as I would have to manually add an entry each time a member registers and associate their unique ID to a unique URL. I need something on the fly as they register where I pass through parameters, for example, and it gives me back a friendly URL for "their" page.

No you wouldn't have to, could you give me examples of the unique id to the unique url you're talking about?

I can then give you some simple code in PHP that'll be able to handle what you're looking for
 
I think you are talking about a normal REST webservice. Maybe have a look at something like http://www.lornajane.net/posts/2012/building-a-restful-php-server-understanding-the-request

otherwise just google for REST & PHP and you should be ok.

The basic idea will be that you need to push the request through some type of process that will take the friendly name from the user and convert it into something else.

over complication for no reason, he needs a max of 5 lines of code on top of his index.php to determine the userid from a member name
 
over complication for no reason, he needs a max of 5 lines of code on top of his index.php to determine the userid from a member name

You don't know that: There might be every reason to overcomplicate it .. :whistle:

And using a good framework is, in my view, way better than hacking a htaccess rule or index hack.
 
You don't know that: There might be every reason to overcomplicate it .. :whistle:

And using a good framework is, in my view, way better than hacking a htaccess rule or index hack.

htaccess was made for this specific purpose, and since it's custom written code, they don't need to hack anything to make it work properly. They just add 5 lines, not an ENTIRE framework that might be cumbersome/useless at the end.

I agree that using a good framework is a good start, but not for a simple website. And even then I'd advocate custom code because the learning curve for someone who never used some magical framework, to take over the work of another programmer, is a lot less than giving them some huge RESTful api PHP database magic connector special that doesn't use htaccess at all just to achieve something as simple and straight forward as an url rewrite!

I'm guessing you have endless amount of issues with resources when you have more than 1 visitor to your site? ;)
 
I'm guessing you have endless amount of issues with resources when you have more than 1 visitor to your site? ;)

Hmm? What issues? On which of my sites? What huge RESTful API? I suspect I know why you don't use REST ...
 
my 1 site does about 80k bot hits and 1000 uniques a day. I run it (in memory, no swapping) on a 256mb CentOS box

Sure it's not a lot of hits for 1 site... but that's not the only site on that box ;)
 
my 1 site does about 80k bot hits and 1000 uniques a day. I run it (in memory, no swapping) on a 256mb CentOS box

Sure it's not a lot of hits for 1 site... but that's not the only site on that box ;)

I believe you have a point there somewhere, I'm just not entirely sure what it is.

The original question is: Implementing friendly URL's like Facebook. How is my recommendation of looking into RESTful services wrong? Sure, and I agree, there are a lot of different ways you can do it, but as a senior software architect with over 20 years of experience, I tend to go for known and trusted frameworks above quick and dirty hacks that nobody can remember, that nobody knows about, and that by the time it needs to be changed, the original developer can not be found anymore.

Did you mention to the OP that htaccess only works on Apache? Or did you just assume that he would always be using a LAMP stack? And why should a developer need to understand web service hacks if they don't need to?
 
but as a senior software architect with over 20 years of experience, I tend to go for known and trusted frameworks above quick and dirty hacks that nobody can remember, that nobody knows about, and that by the time it needs to be changed, the original developer can not be found anymore.

Did you mention to the OP that htaccess only works on Apache? Or did you just assume that he would always be using a LAMP stack? And why should a developer need to understand web service hacks if they don't need to?

I did ask/assumed if he was running linux, and I was correct. Plus, with your seniority and e-penis being so big, you would have known that it's quite a task to re-write your codebase just to move to a different "stack" when you could just stick with what you have/enhance it and that's not to mention the skillset in your personel required to be able to adapt to the new technology.

And if you're going to tell me you can run PHP on a windows server then you immediately lose credibility for that 20 years of experience you bragged about IMO.

The most basics of basics is htaccess on LAMP. So your statement is utter nonsense by implying that you need to *hack* anything and that it is a web service? He doesn't have to learn anything he doesn't want to. htaccess is the most basic thing ever.
 
Thanks guys, will take a look at your replies.

It's a PHP website...all custom code.

htaccess wont work as I would have to manually add an entry each time a member registers and associate their unique ID to a unique URL. I need something on the fly as they register where I pass through parameters, for example, and it gives me back a friendly URL for "their" page.

I would change the vanity URL to something like this: http://website.com/xx/memberuniqeuname. You will then use a generic rewrite rule such as this "RewriteRule ^/in/(.*)$ /UserProfile.php?User_Alias=$1 [L,PT]". In your PHP code you will then need to lookup the vanity name and map it to a real userid. With this you do not need to ever touch RewriteRules.

You could leave the /xx/ out, but then your app would try and map anything against a user profile. BTW - be aware that when you do such a pass-through that you need to look out for SQL injection attacks....
 
I did ask/assumed if he was running linux, and I was correct. Plus, with your seniority and e-penis being so big, you would have known that it's quite a task to re-write your codebase just to move to a different "stack" when you could just stick with what you have/enhance it and that's not to mention the skillset in your personel required to be able to adapt to the new technology.

And if you're going to tell me you can run PHP on a windows server then you immediately lose credibility for that 20 years of experience you bragged about IMO.

The most basics of basics is htaccess on LAMP. So your statement is utter nonsense by implying that you need to *hack* anything and that it is a web service? He doesn't have to learn anything he doesn't want to. htaccess is the most basic thing ever.

Oh, I thought we were measuring when you started with your CentOS. Sorry.

And of course I can run PHP on a Windows server. If you can't, then you have lost all credibility in my view.

Would I want to run PHP on Windows? Well, that is a different question. But, yes, I most definitely can. How many web developers do you give access on your webserver to change htaccess files? Really? Brave man.

And really, really: If you can't say something helpful, then rather stay quiet.
 
Not quite sure how the "i am more clever than you" posts are really helping the OTP...

I actually totally agree. I honestly think REST is a solution worth investigating, and I don't know the OP well enough to determine if it is easier to change a htaccess file, or if it easier to change a logical concept.

But, and this is why I mentioned the experience thing: In my personal experience, it has almost always been better to learn a proper framework then to rely on, call it what you will, I call it hacks. Nice hacks, but still, hacks.

To answer the OP: I would implement friendly URL's with REST and, well, I do implement friendly URL's with REST. It does require you to think a bit more about your system, and it does require you to identify the core functionality and resources as implemented in your system. In my view, these are all very positive aspects of using a proper design framework.

As to some of the other posters / topics: I actually don't care enough to care ...
 
Top
Sign up to the MyBroadband newsletter
X