0

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!

3
  • 4
    The point of these version tags is to prevent caching of old styles/scripts. Why are you trying to remove it? Commented Jul 25, 2009 at 18:49
  • 2
    It is there because that's how it works. Remove it - there's nothing to make it work. The only way to get rid of the version string is not to use it at all and go back to regular last modified/etag version checks. Commented Jul 25, 2009 at 18:57
  • Maybe I should have been more specific. The point of these version tags is not to prevent caching in the way you're thinking it is used as reference as to when to send new header request. Commented Jul 25, 2009 at 19:57

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

Comments

4

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"/>

1 Comment

A file can not be a regular file an a directory at the same time.
3

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.