68 Comments
- srobbin, on 10/12/2007, -1/+61It's a good hack, but more likely they are using Apache's mod_rewrite to conceal their variables and present clean URLs:
http://www.sitepoint.com/article/guide-url-rewriting - mathew_bug, on 10/12/2007, -1/+51You're so right, mod_rewrite has been around for how long? And now they call it 'Digg.com style'? Oh man...
- inactive, on 10/12/2007, -1/+24Yeah WTF is with this article, trying to coin "Digg style URL's" and describing a retarded method for it too. Apache's mod_rewrite is a far more efficient and easier way of achieving the same effect, and is probably what Digg uses anyway.
Seems to me like the article writer either thinks that Digg invented clean URLs, or simply used "Digg" in the title to get to the front page. Obviously a fanboy. Lame. - eplawless, on 10/12/2007, -0/+22well, I'm pleased, so yes. yes it will.
- jues, on 10/12/2007, -8/+26format C: :)
- kozie, on 10/12/2007, -0/+16That basically constitutes most of the viewers here. In the tech section at least.
(I'm pleased as well) - eplawless, on 10/12/2007, -0/+15some people like worrying about things like this
- recipher, on 10/12/2007, -0/+14Digg uses LAMP I believe - Linux, Apache, MySQL, PHP
- dicerandom, on 10/12/2007, -1/+11I bet $5 that if you benchmark this method vs. mod_rewrite you'll find that mod_rewrite is much faster. Native machine code modules > run-time-parsed PHP scripts. Might not be much of a difference with a PHP acceleration engine though.
- mmgm, on 10/12/2007, -0/+8Worst way of achieving this, ever. What the ***** happened to rewrite rules? If Digg really uses that crap (and frankly, I doubt it), someone should be punched in the mouth.
Author obviously has no idea what he's doing and I'd hate for someone to learn from this crap. srobbin already posted a link to a mod_rewrite guide. I dunno how good the guide is, but the method is hundreds of times cleaner and prettier, probably a lot faster too, though I can't say I've benchmarked. Buried as lame. - blastradius, on 10/12/2007, -0/+6At least with mod_rewrite you still get the convenience of having the system maintain your $_GET variables for you. With this "simple" system, you have to go all your variable management manually.
- BerislavLopac, on 10/12/2007, -0/+6"With mod_rewrite, you have to use regular expressions to parse every possible form of a URL you'd ever expect and convert them to the appropriate $_GET variables."
Of course not -- all you need to do is these four lines:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php
This will have the exact same effect as you describe (with the 404 redirection). - bigkm, on 10/12/2007, -1/+7i call them pretty url's :)
- srg13, on 10/12/2007, -0/+6mod_rewrite is much better for this...
- PorkCharSui, on 10/12/2007, -1/+5Any ideas how to accomplish a similar system using IIS?
- geekchic, on 10/12/2007, -0/+4Matt Cutts (Google) recently said on one of his SEO videos that Googlebot will happily spider web pages with up to 3 queries per url.
The idea that query strings kill search spiders died about 5 years ago.
If anything, the idea of using "subfolder" to store your variables could have a negative imapact on SEO as the further the resultant page is from the root, the lower its native importance is deemed to be. Naturally, inbound links etc have a greater positive impact to overule that. - sciencebase, on 10/12/2007, -0/+4Digg style URLs, or whatever you might call them, are "pretty" but underscores are not delimiting characters and to search engine spiders the segment after the final slash just looks like a single string. Hyphens on the other hand delimit keywords in a URL and are much more effective in SEM.
- kefs, on 10/12/2007, -0/+4for iis users:
http://www.eightpence.com/url-rewriting-in-iis/
freeware isapi rewite:
http://cheeso.members.winisp.net/IIRF.aspx - petepete, on 10/12/2007, -0/+3As far as I can tell it is the best approach.
I used an extra column that stores the link-ified title with a regexp to replace punctuation and spaces with underscores. All searching takes place on the original title.
There may be better solutions but this made most sense to me at the time. - mmgm, on 10/12/2007, -0/+3I'd agree with your guess. That makes the most sense.
- zeeneo, on 10/12/2007, -0/+3Say i have an article called: a mule said "hello!".. this would be converted to www.domain.com/dir/a_mule_said_hello
Now i've parsed out a_mule_said_hello what is the *best* way to find this record in the database with certain chars stripped? Should you store the 'a_mule_said_hello' in the table record? Should i try and convert it back and do some kind of half baked match against it which might fail if there are two similar article names?
Any good reliable suggestions would be appreciated! I should look at some existing code and see how they do it but i'm interested in different methods, i'm guessing storing the friendly url in the database is the best approach. - paulmdx, on 10/12/2007, -0/+3I would just have a table mapping parsed name to full name. Either as:
Table: NameLookupTable
Fields: ID, ParsedName
Table: ArticleData
Fields: ID, NameID, FriendlyName,
OR
Table: NameLookupTable
Fields: ParsedName, FriendlyName
When you're adding articles search for identical parsed names and append a number if they're the same.
Let the disagreement commence..... - rdoger6424, on 10/12/2007, -2/+5do you see this button up here? ------------------------------------------------------------------>^^
It's called the reply button. USE IT! - Otto, on 10/12/2007, -0/+3A slightly simpler way:
RewriteRule . index.php [L]
This redirects everything to index.php. Then just parse $_SERVER['REQUEST_URI'] to get what they used for the various bits. It's essentially the same method Wordpress and Drupal and other such scripts use.
Parsing $_SERVER['REQUEST_URI'] is simple, once you know the explode() command. - geminigeek, on 10/12/2007, -1/+4Digg Style URL?
Why not call it Wordpress Style URL?
Wait... wordpress and most blog platforms calls it "friendly url", non calls it digg style url. - diggdisc, on 10/12/2007, -0/+3This is generally useless and just adds overhead to your own work to parse variables . Search engines do store the query parameters, they have to. They also make a url unique. There might be some cases where this is actually useful. I suppose it's useful when you want to HACK in a way to make a controlling page (eg have all url's routed to a single controller, mvc style). Pretty ugly way to package rules into a web app, but hey this is php.
- P5ycHo, on 10/12/2007, -5/+7It has a name.
It's called 'REST' - chris9902, on 10/12/2007, -0/+2IIS MODs have a free URL rewrite plugin for IIS. Works really well but you have to be able to install it so if you don't own your server it's not much good.
http://www.iismods.com/url-rewrite/documentation.htm
You could also try and capture the URL if you're using C# by doing something like this
http://www.stardeveloper.com/articles/display.html?article=2004022801&page=1 - riverrunner, on 10/12/2007, -1/+3codeigniter (a php frameworks) does this nicely. i suppose the others (cake, symfony) do it too.
- mignus, on 10/12/2007, -0/+2yes you can use ISAPI_rewrite http://www.isapirewrite.com/ if you host supports it
- resplence, on 10/12/2007, -0/+2This is the kind of article that would make me feel bad having to digg in order to keep it because of the comments.
- joost538, on 10/12/2007, -1/+3"Search engines do not like those [urls with query parameters]."
Um, yes they do. I went from ?id=1267 style urls to 'clean' ones and indexing/traffic didn't make one bit of difference. It's just an unsubstantiated rumor. At least Google doesn't care if there is a query string. - P5ycHo, on 10/12/2007, -2/+4Dugg down? It's really called REST.
Check it out:
http://en.wikipedia.org/wiki/REST
http://rest.blueoxen.net/cgi-bin/wiki.pl?FrontPage - SirThom, on 10/12/2007, -0/+2For the web geeks among you:
This is how I do it on one of my sites using mod_rewrite:
RewriteRule ^([/_0-9a-zA-Z-]+)$ index.php?x=$1
That way, this one rule matches many possible configurations:
/profile/sirthom
/games/halo-2
/contribute/modify/game/halo-2
Then, I tell my PHP script to sanitize $_GET['x'] (i.e. only "/_0-9a-zA-Z-" are let through, like the RewriteRule), and not to listen to any other $_GET variables.
That way I don't have to keep making new rules for longer URLs as they come along in my code. - surfichris, on 10/12/2007, -0/+1Google and other search engines only care if they're VERY long URLs. They'll start trimming them after a certain length which means some/all of your pages may not be indexed because the trimmed URL may be the same and they're considered duplicates.
Standard URLs with a query string make no difference in rankings these days - you're right, it's basically a rumour.
The advantage though is that it makes URLs easy to read/remember for visitors. (if they're short obviously) They don't need to remember a mass amount of characters in a query string(?, &, = and all of their key/value pairs) - paulmdx, on 10/12/2007, -0/+1Here's a discussion on TheScripts for you:
http://www.thescripts.com/forum/thread127336.html - glitch13, on 10/12/2007, -2/+3Hey! Why follow a standard that's been around since Moses when you can replace it with a hurky mod-rewrite ruleset and a script that creates variables that would have been there anyway, but now they have no names! At least your address bar will look like Digg's!
- lcarsdeveloper, on 10/12/2007, -0/+1That's exactly how I did it.
Say you have a URL:
/albums.php?id=5
You could change it by having a table:
id, name, title
5, "album_name", "Album Name"
Then use the URL:
/albums/album_name/
All you need then is:
SELECT id, title FROM albums WHERE name='album_name'
The advantage of this is if you change the name of the album, the URL won't change, because once 'name' is set, it should stay the same.
You can work out the method of extracting 'album_name' yourself, it's easy enough :) - greyfade, on 10/12/2007, -0/+1@BerislavLopac: Ruby on Rails (where I learned how to do this) uses that very method (with some additional lines to support other scripts that are not called from the dispatch script). From my .htaccess:
RewriteEngine On
RewriteRule ^$ index.php [QSA] # / goes to index.
RewriteRule ^([^.]+)$ $1.php [QSA] # /plan goes to plan.php
RewriteCond %{REQUEST_FILENAME} !-f # everything else...
RewriteRule ^(.*)$ dispatch.rb [QSA,L] # ... goes here.
(Although, looking back, I see now why /images/ goes to the dispatch page instead of the images directory. I should add the !-d condition.) - Alex.w, on 10/12/2007, -2/+3On my sites each article/write up has its own ID. Your like would look like: http://site.com/1050/a_mule_said_hello
The a_mule_said_hello could be anything since teh number is what is matched. - iWasHere, on 10/12/2007, -0/+1But there are some good ones out there.
www.37signals.com - Otto, on 10/12/2007, -0/+1Yes, it would. To prevent this, you can either:
a) Put CSS and images and such in another directory than this one, or
b) Use these rules instead:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
This prevents the rule from taking effect when you're requesting something that is an actual file or directory. - erestar, on 10/12/2007, -0/+1"RewriteRule . index.php [L]"
Wouldn't that prevent css/ and images/ from loading? - gordonchiam, on 10/12/2007, -0/+1yes, there is an routing config file in symfony to configure the url patterns.
- garreh, on 10/12/2007, -0/+1That's what I was hoping this article was about, shame it wasn't. :(
If you look at http://www.sitepoint.com/article/guide-url-rewriting/4 it mentions how to use RewriteMap and a 'lookup' text file to convert urls to ids.
It would be interesting if someone could do a test to see which method is the fastest, Apache's RewriteMap or MySQL table (indexed and possibly memory table?)
I'm afraid of RewriteMap hitting the disk constantly. Any workarounds or tests been done? - mercnboy3, on 10/12/2007, -2/+3good tutorial, if it was 1998...
- dysta87, on 11/26/2008, -0/+0thanks for your information...please to visit :
http://melilea-jakarta.blogspot.com/2008/10/artike ... - bubblegum420, on 10/12/2007, -3/+3@zeeno,
You would just store 'a_mule_said_'... in your database table right after the entry is submitted. When someone goes to you.com/a_mule_said_hello, you would take the second bit and search the db for the article, and if it exists you would display it.
As others have said CodeIgniter (http://www.codeigniter.com) is the best choice for things like these right now. - inactive, on 10/12/2007, -3/+3Nothing new, just a lame blog post.
- ahamx, on 05/13/2009, -0/+0Good for ppl new to web development.
-
Show 51 - 66 of 66 discussions



What is Digg?
Check out the new & improved