开发者

How can I add ?1 to all .js and .css files on the server using .htaccess?

开发者 https://www.devze.com 2023-03-13 06:56 出处:网络
Our web host rece开发者_开发问答ntly updated their media accelerator to start caching .js and .css files. In doing so, they broke some of our client\'s tools on their site because a .js file is not be

Our web host rece开发者_开发问答ntly updated their media accelerator to start caching .js and .css files. In doing so, they broke some of our client's tools on their site because a .js file is not being loaded correctly. They told me that if I can get it to load with ?1 at the end of the URL, it should start loading correctly. However, I have no idea how to do this in the .htaccess. Can anyone help me with this?


This isn't a job for .htaccess.

You need to modify the references to the URLs to add ?1.

You can use .htaccess to cause the URLs to redirect to ?1 versions, but that won't do any good—the browser isn't requesting the URLs in the first place, because they're too cached.


You can put this code in your .htaccess to append ?1 to css and js files like this:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} ^$
RewriteRule \.(css|js)$ %{REQUEST_URI}?1 [R=301,L,NC]


As @SLaks stated, .Htaccess won't work.

Even if you did add ?1 on with htaccess, your browser would then cache that too.

If the JavaScript/Css file is cached there should be no problem with it as the browser would just load the cached files.

One way to get round it would be to do something like:

<script type="text/javascript" src="file.js?"<php echo date("ymdhis");?> />

without the need for .Htaccess

0

精彩评论

暂无评论...
验证码 换一张
取 消