NikitaTratorov
@NikitaTratorov
CTO

Почему IIS переадресует (Rewrite) HTTPS запрос на порт 80?

Идея в том, чтобы перенаправлять все прямые попытки скачать файл на специальный адрес: https://mysite.com/getfile/?fname=media/upload/use...}
Трудности отладки rewrite в Azure, не позволяют мне докопаться до истины. Может быть Вы сможете заметить где грабли?

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
		<staticContent>
			<remove fileExtension=".woff" />
			<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
            <remove fileExtension=".ttf" />
            <mimeMap fileExtension=".ttf" mimeType="application/octet-stream" />
            <remove fileExtension=".svg" />
            <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
            <remove fileExtension=".gif" />
            <mimeMap fileExtension=".gif" mimeType="image/gif" />						
			<remove fileExtension=".jpg" />
            <mimeMap fileExtension=".jpg" mimeType="image/jpg" />	
            <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="0.01:00:00" />
	    </staticContent>
        <urlCompression doStaticCompression="true" />	
		<rewrite>
			<rules>
				<clear />
													
                <rule name="Redirect to https" stopProcessing="true" enabled="true">
                    <match url="(.*)" />
					<conditions logicalGrouping="MatchAny">
					  <!--<add input="{SERVER_PORT_SECURE}" pattern="^1$" />
					  <add input="{SERVER_PORT_SECURE}" pattern="^0$" />-->
					  <add input="{HTTPS}" pattern="off" ignoreCase="true" />	
					</conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="true" />
                </rule>	
					
				<rule name="Redirect to non-www1" stopProcessing="true" enabled="true">
					<match url="(.*)" negate="false" />
					<conditions>
						<add input="{HTTP_HOST}" pattern="^mysite\.com$" negate="true" ignoreCase="true" />
					</conditions>
					<action type="Redirect" url="https://mysite.com/{R:1}" redirectType="Permanent" />
				</rule>
				
				<!--
				Этот блок должен всегда выполняться при попытке прямого доступа в папку /media/upload/users/
				но IIS почему-то перенаправляет запросы неправильно, и результирующий всегда выглядит как
				https://mysite:80/media/upload/users/...
				и на странице показывает ошибку 404.4
				Проблема в том, что HTTPS это порт 443.
				-->	
				<rule name="Rewrite to getfile" stopProcessing="true" enabled="false">
                    <match url="^media\/upload\/users\/(.*)$" />
					<action type="Rewrite" url="//getfile/?fname=media/upload/users/{R:1}" />
                </rule>			
				
				<rule name="Imported Rule 1" enabled="true">
					<match url="^(.*)$" ignoreCase="false" />
						<conditions>
							<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
							<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
							<add input="{R:1}" pattern="^(index.php|robots.txt)" ignoreCase="false" negate="true" />
						</conditions>
						<action type="Rewrite" url="index.php/{R:0}" />
				</rule>
				
				<rule name="Imported Rule 2" stopProcessing="true" enabled="true">
					<match url="^(application|modules|system)" ignoreCase="false" />
						<conditions>
							<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
						</conditions>
						<action type="Rewrite" url="index.php/{R:0}" />
				</rule>
				
			</rules>
		</rewrite>
	</system.webServer>
    <connectionStrings>
        <add connectionString="database=mydb;server=mydbserver;uid=username;pwd=password" name="dbname" providerName="MySql.Data.MySqlClient" />
    </connectionStrings>
</configuration>
  • Вопрос задан
  • 3261 просмотр
Решения вопроса 1
ahriman
@ahriman
Технологический евангелист Microsoft
Не это ли правило?
rule name="Redirect to https" stopProcessing="true" enabled="true"
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы