N
N
Nikita Tratorov2015-01-24 19:56:49
IIS
Nikita Tratorov, 2015-01-24 19:56:49

Why is IIS redirecting (Rewrite) HTTPS request to port 80?

The idea is to redirect all direct attempts to download a file to a special address: https://mysite.com/getfile/?fname=media/upload/use... }
The difficulty of debugging rewrite in Azure prevents me from getting to the bottom of it. Maybe you can see where the rake is?

<?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>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Belotserkovsky, 2015-03-17
@NikitaTratorov

Isn't that the rule?
rule name="Redirect to https" stopProcessing="true" enabled="true"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question