As to your first question, are you asking about the link tag or the way the script linked returns the CSS? It appears to be a relatively generic script receiving a GET string, processing it and returning a stream of CSS to be included in the document.
The W3C, I'm not positive, but I think the 'W3C-WD' is the stylesheet. It just doesn't have the .css extension.
For the CSS file with a versioning string, it's simply to make sure that when a new version of the CSS file is uploaded people can immediately see the changes (because the URL will change) since the cache won't be made for that particular URL. A simple solution would be to load in the specified CSS file (using Apache, PHP, etc.) or a default one if it does not exist (or 404 ;)).
With the stylesheet on the W3C site, the correct file will show up because their web server is using Content Negotiation (Apache). Full details are at the 'Apache' link just posted, but essentially (depending how you have things set up) Apache will look for files in that location and deliver the best match, if any. For example, on my local server I can access http://localhost/mydir/myfile which might call a PHP script if there is a myfile.php available. If I created a myfile.html and accessed the same URL, the displayed page would be the HTML document because that overrules the PHP file. If I got rid of the HTML and PHP file but instead placed a myfile.png there, the same URL would display the image. (Note: This is not mod_rewrite!)
If you try to access http://www.w3.org/StyleSheets/TR/W3C-WD.css then you'll get the stylesheet. If you try instead to access http://www.w3.org/StyleSheets/TR/W3C-WD.html, you'll get a 300 Multiple Choices header with in this case a list of available files.
The Following User Says Thank You to Salathe For This Useful Post:
That's a small snippet of some rules I'm using right now in developing my site. This is doing a few things; first and foremost, all my urls are readable and SEO friendly. Secondly, it's adding another minor level of security to my scripts. None of my scripts use GET, so GET can't be abused. On top of that, thanks to the regular expressions, if the URL doesn't conform to the guidelines above, the user just gets a 404 returned, so it's harder to inject malicious data. All input, whether from this method or POST is sanitized and validated internally as well, but all the little extras I've implemented add up to what I believe to be a pretty bulletproof operation.
mod_rewrite is damned cool, IMHO.
Last edited by delayedinsanity : 04-28-2008 at 04:30 PM.
yea mod_rewrite can be used for alot, a few of my favorites is getting myspace to post some dynamic images on my site, since they block .php extensions in files
its good for SEO, since google and other sites thing page.php?id=1 and page.php?id=2 is the same page if you wanted forums and such to get crawled youd need a modrewrite to make page-1.php and page-2.php although id make that prettier. This site even uses it for SEO
You're wrong. Google understands dynamic links. There's no need to respond to this thread anymore unless you have something important to say about dynamic stylesheet links. This isn't about mod_rewrite.
However, thanks for all of your help :P
Signatures are nothing but incriminating.
Whoah, somebody had a bad date with mod_rewrite. Why all the hostility?
Google understands them, google just doesn't care for them. So if you want to rank higher, you won't use dynamic links. Plus, if you want your site to be more user-friendly, you won't use them. Plus, if you want your site to be a little more secure from front-door attacks, you won't use them. Plus, I could go on forever.
Have you ever once had a conversation in person that didn't start on one topic and end on another? Relax.
Are you running a test machine that does that, or is it on a remote host? Because it sounds to me like the module just isn't loaded in - for some stupid reason mod_rewrite is shipped with apache but not turned on (well, I think it's stupid). If you're on your own box, you can open up httpd.conf and edit this line:
#LoadModule rewrite_module modules/mod_rewrite.so
.. remove the # and you get ..
LoadModule rewrite_module modules/mod_rewrite.so
And then as long as allowoverrides is on, you can mod_rewrite to your hearts content. If your host doesn't have it on however, like I just discovered (#@$@#$@) then you may be outta luck. Which is why I wish Apache had it turned on by default, because then my host probably would too, and I could happily use it while they sat in their nice little air conditioned offices thinking they was the shiznit.