views:

266

answers:

3

Hello,

I was wondering if it's at all possible to run a RewriteRule that will hide a CSS version in a link tag.

Ex.

link href="css/global.css?v=1.2.3" rel="stylesheet" type="text/css"

To show up as Ex.

link href="css/global.css" rel="stylesheet" type="text/css"

I can't seem to find anything on this subject and everything I've attempted sends a 500 Error :(

Thanks!

+4  A: 

No, you can't do that. You're misunderstanding what RewriteRule does; it doesn't change the HTML you're producing, it changes how incoming link requests are handled.

More generally, you can't remove the version from CSS or JS files without defeating the entire reason the versioning is there (so people automatically obtain any new version you publish instead of running your side with old, maybe broken cached files).

chaos
+1  A: 

Such a versioning is often used to build unique URIs that the client didn’t know yet. That is to force the client to request that resource instead of using a cached version.

If you now want to remove that version information, the URI would not be unique any more and the client may not make a request but use a cached version. But that’s probably not what you want, otherwise you wouldn’t use that version information, would you?

Gumbo
+3  A: 

well I dont see the problem on having a version on the url but maybe this can help you

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^css/(.*)/(.*)\.css$ /css/$2.css?v=$1 [QSA]

this allow you to do:

<link href="/css/1.2.3/global.css" rel="stylesheet" type="text/css"/>
Gabriel Sosa
A file can not be a regular file an a directory at the same time.
Gumbo
@Gumbo you were right, I fixed the code thank you so much!
Gabriel Sosa