<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<system.webServer>

		<!-- Prevent web access to all files in the /config/ directory -->
		<security>
		  <requestFiltering>
		    <hiddenSegments>
		      <add segment="config"/>
		    </hiddenSegments>
		  </requestFiltering>
		</security>

    <!-- X3 rewrite rules -->
    <rewrite>
			<rules>

				<!-- Rewrite any calls to *.html, *.json, *.xml, *.atom or *.rss if a folder matching * exists -->
				<rule name="Rewrite any calls to *.html, *.json, *.xml, *.atom or *.rss if a folder matching * exists" stopProcessing="false">
			    <match url="(.+)\.(html|json|xml|atom|rss)$" ignoreCase="false" />
			    <conditions logicalGrouping="MatchAll">
		        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
			    </conditions>
			    <action type="Rewrite" url="{R:1}/" />
				</rule>

				<!-- Add a trailing slash to directories -->
				<rule name="Add a trailing slash to directories" stopProcessing="false">
			    <match url="([^/]+)$" ignoreCase="false" />
			    <conditions logicalGrouping="MatchAll">
		        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
		        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
		        <add input="{URL}" pattern="(\.|\?)" ignoreCase="false" negate="true" />
		        <add input="{URL}" pattern="(.*)/$" ignoreCase="false" negate="true" />
			    </conditions>
			    <action type="Rewrite" url="{R:1}/" />
				</rule>

				<!-- Rewrite any calls to /render to the image parser -->
				<rule name="Rewrite any calls to /render to the image parser" stopProcessing="false">
					<match url="^render/." ignoreCase="false" />
					<conditions logicalGrouping="MatchAll">
						<add input="{URL}" pattern="render/" ignoreCase="false" />
						<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
					</conditions>
					<action type="Rewrite" url="app/parsers/slir/" />
				</rule>

				<!-- Rewrite routes to index.php if they are non-existent files/dirs -->
				<rule name="Rewrite routes to index.php if they are non-existent files/dirs" stopProcessing="false">
					<match url="^(.*)/$" ignoreCase="false" />
					<conditions logicalGrouping="MatchAll">
						<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
						<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
					</conditions>
					<action type="Rewrite" url="index.php?/{R:1}/" appendQueryString="true" />
				</rule>

			</rules>
		</rewrite>
	</system.webServer>
</configuration>