Implementing friendly URL's like Facebook has for user profiles

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.

I was extremely helpful giving him (the dev) the knowledge to simply and EASILY implement what he wanted without having to add-on several hours/weeks of dev time to implement a new framework.

Of course you CAN run PHP on Windows... :rolleyes: you'll just be a dumbass if you did.

Since he is the dev for this project, I assumed he already has access to htaccess. Not sure about how your policies work, but we usually have a hierarchy when it comes to making things live with dev/test/live environments and full test cycles.

It's really a 5 minute process for him to get url rewriting done as simply/cheaply/easily if he'd like. MagicDude4Eva had a good point to use /xx/ instead, but it's pretty easy setting up 1 rule in htaccess to rewrite everything to 1 PHP file, then have that 1 PHP file determine where to rewrite to, an example is:

$uri_arr = array();
$uri = $_SERVER['REQUEST_URI'];
$uri_arr = explode('/',$uri);
$uri_arr = array_filter($uri_arr); //remove any empty elements
$uri_arr = array_values($uri_arr); //reset key values to exclude any null references

switch (count($uri_arr)) {
case 1:
//1 http://example.com/keyword
$keyword = str_replace("-"," ",$uri_arr[0]);
include($_SERVER['DOCUMENT_ROOT']."/detail.php");
break;

....etc

Many ways he can do it. I gave him the simplest/easiest method

And just to touch on htaccess "access" again. If you follow proper best practices, security will never be an issue even if you give a total n00b access to your .htaccess file.
 
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 ...

Whatever big man. Bet you just love throwing your weight around in that small pond you call a dev team
 
Acid: Let's not side track the original OP too much. Let's just agree that we don't agree, ok?
 
For me the main decision would be to look at the current application. I would guess that a RewriteRule is the fastest most uncomplicated way to address it. I am not quite sure why people consider URL rewriting hacks - in most cases your loadbalancers will work on the same principles (i.e. balance load based on traffic origin, user groups etc).

Anyone not using Rewrite rules is either so damn good and has designed everything 100% correct and their websites will never evolve to changing SEO requirements. I for one love them, as I can do anything I like on the edge of the network without having to change code.
 
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.

What I do is route all my URLs to a single function to process these tidy URLs. I then use the PHP function to determine what to do next.

EDIT: CrazyFig, how much code have you already done? It might be worth it to consider moving to a framework like codeignitor
 
Last edited:
Thanks again for the help guys ;)

Yeah...the unique ID is mem_id, just like the example. Website is not live...so I cant show and live example, but everything is correct except for the domain name. The username is unique.

Does that help, let me know if you need more info?

Cheers
CF
 
Thanks again for the help guys ;)

Yeah...the unique ID is mem_id, just like the example. Website is not live...so I cant show and live example, but everything is correct except for the domain name. The username is unique.

Does that help, let me know if you need more info?

Cheers
CF

Nope, you're well on your way to get what you want out of it. Go through my posts with code examples and go from there. Also consider MagicDude4Eva's advice re: having a url like this: domain.co.za/user/username instead of domain.co.za/username

This will help in growing your link profile down the line, so if you want to add a different section, you could, like domain.co.za/pages/blog-page-1

Otherwise consider cbrunsdonza's advice as well as the code I posted last. Basically you'll have 1 rewrite rule go to 1 page. That page then takes the url and breaks it up into workable pieces, and depending on it's structure, send it to different php pages for further processing.
 
Nope, you're well on your way to get what you want out of it. Go through my posts with code examples and go from there. Also consider MagicDude4Eva's advice re: having a url like this: domain.co.za/user/username instead of domain.co.za/username

This will help in growing your link profile down the line, so if you want to add a different section, you could, like domain.co.za/pages/blog-page-1

Otherwise consider cbrunsdonza's advice as well as the code I posted last. Basically you'll have 1 rewrite rule go to 1 page. That page then takes the url and breaks it up into workable pieces, and depending on it's structure, send it to different php pages for further processing.

Awesomeness....plenty to work with!

Dankie, dankie guys! :D
 
@OP, what you looking for is called vanityurl's, this is done using HTACCESS file, and no you won't need to rewrite for each member, you just have a specific referral indentifier. I speak from experience because we created a custom website (Student Commune) that uses vanityurl's for users like Twitter, Facebook and Instagram.

Example would be www.studentcommune.co.za/studentcommuneguy, and haven't found any glitches with it yet.

All the best on making it work for you.
 
LOL Ok so this is what its called URL Rewriting i will remember this :-)

I also wanted to do url re writing so instead i had the below work around

If a URL was http://mybroadband.co.za/vb/showthr...dly-URL-s-like-Facebook-has-for-user-profiles

I would turn it into http://mywebsite.co.za?URL=1234
by saving the long URL and short url into a MySQL table.

Then redirect 1234 with a SQL lookup. back to the long one.

Like this


<?
$MyURL = $_GET["URL"];

$LongURL = select * from URLS where SHORT_URL = $MyURL


php header('Location:$LongURL');

?>



I would
 
LOL Ok so this is what its called URL Rewriting i will remember this :-)

I also wanted to do url re writing so instead i had the below work around

If a URL was http://mybroadband.co.za/vb/showthr...dly-URL-s-like-Facebook-has-for-user-profiles

I would turn it into http://mywebsite.co.za?URL=1234
by saving the long URL and short url into a MySQL table.

Then redirect 1234 with a SQL lookup. back to the long one.

Like this


<?
$MyURL = $_GET["URL"];

$LongURL = select * from URLS where SHORT_URL = $MyURL


php header('Location:$LongURL');

?>



I would

That requires too many resources for what you want to do (very simply) within code and/or just Apache, which has the functionality built in.

However, where this will be useful is something like tiny URL's which shortens any url into a small one, it saves the tiny url reference with the url it should go to and does a redirect.

Your database should be used for stuff like user logins or whatever else you'd like to store down the line, not lookups to url rewrites that can be done in any number of ways (as demonstrated)
 
That requires too many resources for what you want to do (very simply) within code and/or just Apache, which has the functionality built in.

However, where this will be useful is something like tiny URL's which shortens any url into a small one, it saves the tiny url reference with the url it should go to and does a redirect.

Your database should be used for stuff like user logins or whatever else you'd like to store down the line, not lookups to url rewrites that can be done in any number of ways (as demonstrated)

Tinyurl.com does some sort of url rewrite.

I.E
http://tinyurl.com/1c2

maybe they are writing to their apache config file as people create tiny URLs
 
Tinyurl.com does some sort of url rewrite.

I.E
http://tinyurl.com/1c2

maybe they are writing to their apache config file as people create tiny URLs

no the way they do it is what you describe how'd you do the "rewrite"

FYI, what you do is more of a redirect than a rewrite (which also works) but there is no need for you to have stored that information in a database and do a lookup UNLESS you did something like tinyurl does (which is shorten the url for you, they need to have a reference as to what they shortened, so they store it in a database)

Then once they retrieve that record, they do a *redirect*, the URL actually changes. With a URL *rewrite* the URL doesn't change, but it fetches data from another page altogether.

Think that is where the confusion here lies :)
 
Top
Sign up to the MyBroadband newsletter
X