cannot display svgz files correctly in browser - svg

I try to display a svgz file like this...
<object id="svgimage" data-imagepath="Images/file.svgz"></object>
But the only thing displayed is a bunch of weird characters shown in the image below..
In my IIS I do have mimetype for svgz and svg so that is correct, but why isn't the svgz file displayed correct?
UPDATE:
It does help to include this rule in web.config. But this only works if I have the svgz file in a subfolder of the webb application. If I try to use a svgz file that is another site (but on the same server) it does not work.
<rewrite>
<outboundRules>
<rule name="Rewrite SVGZ header" preCondition="IsSVGZ" stopProcessing="true">
<match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
<action type="Rewrite" value="gzip" />
</rule>
<preConditions>
<preCondition name="IsSVGZ">
<add input="{PATH_INFO}" pattern="\.svgz$" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
I use IIS Version 21H (OS build 22000.708)

Related

IIS - setting cache-control header per file type

I'd like to set different cache-control header values for my js,css and html files.
I know about the option to set it on a per-folder basis but my app has html and js files in the same folder.
Is it even possible in IIS ?
This is possible in IIS 7+ using IIS outbound rewrite rules. Eg. if you want to invalidate all .html pages, create the following outbound rule (after installing the IIS rewrite module) in the outboundRules section of the web.config:
<outboundRules>
<rule name="AdjustCacheForHTMLPages" preCondition="IsHTMLFile">
<match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
<action type="Rewrite" value="no-cache, no-store, must-revalidate" />
</rule>
<preConditions>
<preCondition name="IsHTMLFile">
<add input="{REQUEST_FILENAME}" pattern=".*\.html" />
</preCondition>
</preConditions>
</outboundRules>
The answer by #jotap will only work for file requests that end in ".html". I needed it to work for the content type, too:
<outboundRules>
<rule name="AdjustCacheForHTMLPages" preCondition="IsHTML">
<match serverVariable="RESPONSE_CACHE-CONTROL" pattern=".*" />
<action type="Rewrite" value="no-cache, no-store, must-revalidate" />
</rule>
<preConditions>
<preCondition name="IsHTML" logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" pattern="\.html$" />
<add input="{RESPONSE_CONTENT-TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>

static url rewrite, using rewrite map is not working

I have a website on azure, and I am trying to make some user-friendly urls to my websites use.
I have downloaded IIS remote manager, and did as it was explained here.
Although the article is since 2008, the GUI of the remote IIS manager is still almost the same.
after defining the rewrite map, and the rule that looks inside the map, this is the web.config that was generated:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<outboundRules>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
<rewriteMaps>
<rewriteMap name="StaticRewrites">
<add key="/niceurlpart" value="/Menu/master/#/Menu?Token=7926983e-c64e-4547-85f5-d85e3c06c7a8" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Rewrite rule1 for StaticRewrites" patternSyntax="ExactMatch">
<match url=".*" />
<conditions>
<add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
when I enter inside the address bar: mydomain.com/niceurlpart I get:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
Also, when I try to test the pattern inside the remote IIS manager, it fails..
am I missing something?
Not sure on the syntax of doing this in web.config, but the # part of a URL doesn't reach the server, so using that in your rule won't work.
If you are using angular type app and are using # for routing, then try using HTML5 mode which will get rid of the hash.
If your are after SEO, you can google '_escaped_fragment_' to get the hash value to your server. Also if SEO is your goal then we use _escaped_fragment_, along with this tool https://prerender.io

Outbound IIS Rewrite Rule to set Content Type Response Header

Trying to get IIS to rewrite the response content type from image/jpeg to application/octet-stream for requests to resources like this:
http://www.example.org/path/to/images/some-image.jpg#download
to respond with the content type of application/octet-stream so browsers will prompt for download. I'm trying not to have to write a handler in the application to do it and having IIS do it would be easier.
Here is what I have so far:
<outboundRules>
<rule name="Download Photos" preCondition="Photo Images">
<match serverVariable="RESPONSE_CONTENT_TYPE" pattern="image/jpeg" />
<action type="Rewrite" value="application/octet-stream" />
</rule>
<preConditions>
<preCondition name="Photo Images">
<add input="{REQUEST_LOCATION}" pattern="photos/.*\.jpg\?#download$" />
</preCondition>
</preConditions>
</outboundRules>
Your problem is that # is available in the browser only. The server can not read it. You can read more about that in Wiki: https://en.wikipedia.org/wiki/Fragment_identifier

Adding a "fake" root folder using rewrite

I'm not sure where to go on this one. I've got rewrites to remove file extensions and such but what I can't seem to find out how to do is to add a "fake" root directory to the site. For example if the site is www.foo.com/index.htm I'd like to rewrite the URL to show www.foo.com/root/index.htm. I can use either the IIS rewrite module or mod rewrite I'm just uncertain on how to go about this (or if it's even possible) and my google-fu has failed me.
If I understand it correctly, you want requests to come with root prefix. In that case this rewrite will do it:
<rule name="StripRoot" stopProcessing="true">
<match url="root/(.*)" />
<action type="Rewrite" url="/{R:1}" />
</rule>
To modify the html served to the client outbound rule is required:
<outboundRules>
<rule name="FakeRoot" preCondition="IsHtml">
<match filterByTags="A, Area, Base, Form, Frame, IFrame, Img, Input, Link, Script" pattern="http://www\.foo\.com/(.*)" />
<action type="Rewrite" value="http://www.foo.com/root/{R:1}" />
</rule>
<preConditions>
<preCondition name="IsHtml">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
It assumes that you have fully qualified URL in tag attributes, if relative links are used you need more sophisticated rewrites.

using svgz in html server

I use chrome to visualize a svg file which I put on a server, that works fine. Here's the dead simple html for it:
svg
However, when I try to use svgz instead, it doesn't work. Here's the code I use:
svgz
Here the error:
This page contains the following errors:
error on line 1 at column 1: Encoding error
Below is a rendering of the page up to the first error.
Looks to me that the browser doesn't decompress the file first.
Any idea how can I make this (much smaller) svgz file to display nicely on my browser?
I had to add a .htaccess in the web folder root with the following content:
AddType image/svg+xml svg
AddType image/svg+xml svgz
AddEncoding x-gzip .svgz
From those 2 links here and here
The info on this page solve my problem with IIS
http://forums.iis.net/t/1175276.aspx/1
<system.webServer>
<rewrite>
<outboundRules>
<rule name="Rewrite SVGZ header" preCondition="IsSVGZ" stopProcessing="true">
<match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
<action type="Rewrite" value="gzip" />
</rule>
<preConditions>
<preCondition name="IsSVGZ">
<add input="{PATH_INFO}" pattern="\.svgz$" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
</staticContent>
</system.webServer>
It looks like it's fixed in build 13536 and greater ⟨http://code.google.com/p/chromium/issues/detail?id=9737⟩ so I guess you just have to upgrade the browser?

Resources