TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   XHTML, HTML, CSS (http://www.talkphp.com/xhtml-html-css/)
-   -   Whats with the weird external stylesheet links? (http://www.talkphp.com/xhtml-html-css/2620-whats-weird-external-stylesheet-links.html)

Aaron 04-12-2008 01:53 AM

Whats with the weird external stylesheet links?
 
Okay... Please share the secret. Why and how do they do this:
<link rel="stylesheet" type="text/css" media="all" href="http://<snip>.com/?css=styles/index.v.1195440872" />

and also, whats with the W3C.... How did they make a stylesheet do this:

http://www.w3.org/StyleSheets/TR/W3C-WD

They just link to the directory and it goes to the stylesheet. I feel violated. This goes against everything I was taught in elementary school!

SOCK 04-12-2008 03:44 AM

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.

Aaron 04-12-2008 03:50 AM

The way the script returned the CSS, and why it was used that way.

sidisinsane 04-12-2008 08:36 AM

Quote:

Originally Posted by Aaron (Post 13395)
... How did they make a stylesheet do this:

http://www.w3.org/StyleSheets/TR/W3C-WD ...

I'm sure there are several ways of doing this. One would be to place an index.php in the W3C-WD directory, which is parsed as css by sending a CSS header. Like this:
Code:

<?php
// Send CSS header
header("content-type: text/css");
header("Expires: ".gmdate("D, d M Y H:i:s", (time()+900)) . " GMT");

// Your styles
...
?>


Salathe 04-12-2008 09:51 AM

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.

Garrett 04-12-2008 09:58 PM

I used a similar method, to allow quick access to editing the CSS from the database. I just used a text/css header in PHP and outputted the CSS.

Same thing goes with RoR, look at:
Code:

<link href="http://asset2.projectpath.com/stylesheets/cache/all.css?1207968108" media="screen" rel="stylesheet" type="text/css" />
<link href="http://asset3.projectpath.com/stylesheets/print/application.css?1207968082" media="print" rel="stylesheet" type="text/css" />


Aaron 04-13-2008 08:22 PM

Wouldn't you have to link to a .php file? I mean, linking to .css would lead you to a file not there, but linking to a .php file would give you a css file, wouldn't it?

d4v1d 04-23-2008 11:15 AM

mod Rewrite :)

Aaron 04-27-2008 08:13 PM

mod rewrite is overrated and queer.

TlcAndres 04-27-2008 08:24 PM

I do admit that mod_rewrite's syntax is a bit odd but it's dead useful.

Aaron 04-27-2008 09:59 PM

useful for what?

delayedinsanity 04-27-2008 10:23 PM

A LOT.

Code:

RewriteRule ^users/info/([A-Za-z0-9_]+)/?$ users/info.php/$1
RewriteRule ^users/([A-Za-z0-9]+)/?$ users/$1.php

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.
-m

blayne4k 04-28-2008 03:40 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

Aaron 04-28-2008 08:44 PM

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

delayedinsanity 04-28-2008 08:57 PM

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. ;-)
-m

Aaron 04-28-2008 09:06 PM

All the hostility is as soon as I put in
Code:

RewriteEngine on
I get a 500 internal server error.

edit: just turned on the rewrite module. Now my problem is the weird regex that I have to learn.

delayedinsanity 04-28-2008 09:12 PM

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.
-m

Jim 05-08-2008 07:57 AM

After loading the module, reboot your apache server.

Orc 05-08-2008 08:44 AM

Quote:

Originally Posted by Aaron (Post 14062)
All the hostility is as soon as I put in
Code:

RewriteEngine on
I get a 500 internal server error.

edit: just turned on the rewrite module. Now my problem is the weird regex that I have to learn.

It's not that hard, I learned it in like 5 minutes.


All times are GMT. The time now is 07:35 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0