Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add custom header based on file type

We are trying to add a custom header (X-Robots-Tag) for sitemap files in IIS 7.5. However, it does not appear that IIS supports custom headers based on a file type or wildcard (only subfolders).

Can we add a custom header for only *.xml.gz files via Web.config?

We would like to avoid making the customization via code or on our load balancer.

like image 215
Matt Beckman Avatar asked Mar 01 '12 19:03

Matt Beckman


People also ask

Is it possible to add custom header?

In the Home pane, double-click HTTP Response Headers. In the HTTP Response Headers pane, click Add... in the Actions pane. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.

Can AWS ALB add custom header?

As far as I know there is no way to set custom headers at the ALB level. You can however add CloudFront as a CDN in front of it, that allows you to set custom headers, which will then be passed on to the ALB.

How do I add a custom header to all requests?

Under Custom request headers, click Add header. Enter the Header name and Header value for the custom request header. Enter any additional custom request headers. Click Save.

How do I add HTTP response header?

Select the web site where you want to add the custom HTTP response header. In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add. In the Name box, type the custom HTTP header name.


1 Answers

You can use the IIS UrlRewrite module and add a custom outbound rule to configure the custom header. Here is a sample rule you may want to use:

  <system.webServer>     <rewrite>       <outboundRules>         <rule name="Set custom HTTP response header">           <match serverVariable="RESPONSE_X_Robots_Tag" pattern=".*" />           <conditions>             <add input="{REQUEST_URI}" pattern="\.xml\.gz$" />           </conditions>           <action type="Rewrite" value="The value you need for this header"/>         </rule>       </outboundRules>     </rewrite>   </system.webServer> 

More info: UrlRewrite documentation

like image 56
Efran Cobisi Avatar answered Sep 26 '22 05:09

Efran Cobisi