PDA

Click to See Complete Forum and Search --> : [RESOLVED] DIGG.COM's url formatting - how to.


blowman
May 29th, 2008, 01:02 PM
I am sorry for the slightly weird title to this thread, but I honestly have no way of explaining it without giving examples as I know not what this technique is called.

Go to Digg and take a look at any random story's comments. After (mostly) cringing at the ridiculous comments and knowing that little extra about politics, notice the URL.

http://digg.com/politics/This_is_boring_us_to_death

It looks as if the page is index.php (or similar) in the folder "This_is_boring_us_to_death", but I am also sure I've seen some kind of technique that makes the end user unaware of what the file name for the page is, and what language was used to create that page...etc.

:confused:

Basically, do websites like digg.com literally create a new folder, name it the story title and then put the content in one page inside that, or is there another way of doing it so the URL looks like digg's? Even the name of this little feature would be good, so I can research it more.

Once again, apologies for the crappy title and explanation :( If nobody understands it I'll try and re-write it.

RudiVisser
May 29th, 2008, 01:19 PM
No, it's called Rewrite rules on the web server.

Apache = mod_rewrite
IIS = ISAPIRewrite
Lighttpd = Built in

You can rewrite URLs such as /politics/* to index.php?page=*, then handle it accordingly.

For example you could have something like /hello-world/ redirect to hello-world.php.

I_Love_My_Vans
May 29th, 2008, 01:20 PM
I dont like to say this, mainly because I think I do it wrong, but I have used a method like this.

I have a URL, e.g. http://www.mysite.com/Never_guess_what,

As this 'directory' doesnt exist it fires a 404 error, I then catch that error, query the URL and redirect to the page of choice.

Of course on your server you have to be able to control your 404 (400, 403, 500 errors), but if you can do that send the error to a custom script, grap the URL using the $_SERVER variable and boom, sorted.

penagate
May 29th, 2008, 09:30 PM
I dont like to say this, mainly because I think I do it wrong

Yeah, you are doing it wrong. Your method will probably (depending on the web server) still send a 404 status code back to the client. Although this probably won't affect a human, it will mean that any automated tool — such as a search engine crawler — will think that no page exists at that address.

The rewriting option is the correct method of achieving proper virtual URIs as this does not affect the status code.

Example for Apache:
RewriteEngine On
RewriteRule ^.*$ /home/www/index.php [L]


That will pass all requests through to /home/www/index.php. You can then parse the variable $_SERVER['REQUEST_URI'] and serve the appropriate content.

blowman
May 31st, 2008, 07:46 PM
RudiVisser:
Ah, apache. Thinking about it logically it would have to be that :blush: (unless you processed 404's, as I_Love_My_Vans said) lol. Oh well, this information is exactly what i need, thank you very much! :afrog:

I_Love_My_Vans:
Even though i will be going with the mod_rewrite way, this is still a work-around i did not think of. Always nice to know :thumb:

penagate:
Thanks for the examples and more detailed explanation! :D