2017-04-10 4 views
2

내 웹 사이트를 http에서 https로 리디렉션하도록 내 web.config에서 리디렉션 규칙을 만들었습니다. 내가 가진 문제는 웹 사이트의 모든 단일 링크가 이제 https라는 것입니다. SSL이 없으므로 인증서 오류가 발생하는 다른 웹 사이트에 대한 링크가 많습니다. 이것이 내가 한 일입니다.ASP.NET 코어가 http를 https로 리디렉션

<rewrite> 
    <rules> 
    <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true"> 
     <match url="(.*)" /> 
     <conditions logicalGrouping="MatchAny"> 
     <add input="{SERVER_PORT_SECURE}" pattern="^0$" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
    </rule> 
    </rules> 
</rewrite> 

내 웹 사이트의 모든 링크가 아니라 내 도메인에만 https를 리디렉션 할 수 있습니까? 당신은뿐만 아니라 도메인에 대한 또 다른 조건을 추가 할 수 있습니다

+0

https://finalcodingtutorials.blogspot.ae/2017/03/non-www-to-www-with-http-to-https .html –

+0

여기 좀보십시오 : https://neelbhatt.com/2018/02/04/enforce-ssl-and-use-hsts-in-net-core2-0-net-core-security-part-i/ – Neel

답변

1

,

<add input="{HTTP_HOST}" negate="true" pattern="localhost" /> 

도메인 이름으로 "localhost"를 교체합니다. 이 도움이

자세한 내용은
<rewrite> 
    <rules> 
    <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true"> 
     <match url="(.*)" /> 
     <conditions logicalGrouping="MatchAny"> 
     <add input="{SERVER_PORT_SECURE}" pattern="^0$" /> 
     <add input="{HTTP_HOST}" negate="true" pattern="yourdaomainname" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
    </rule> 
    </rules> 
</rewrite> 

,

https://www.softfluent.com/blog/dev/2016/12/27/Page-redirection-and-URL-Rewriting-with-ASP-NET-Core

희망!

+0

고마워요! 하지만 지금은 내 웹 사이트에 문제가 있습니다. HTTP 500 오류가 있습니다. 모든 재 작성 규칙을 제거하고 내 web.config를 설정하려고했지만 HTTP 500 오류가 계속 발생합니다. 나는 또한 모든 것을 설정하려고했지만 여전히 작동하지 않습니다 ... 나는 그 문제를 해결하는 방법을 모르겠습니다. – Huby03

+0

오류에 대한 자세한 내용을 알려주십시오. –

+0

나는 내 문제를 자세히 설명하는 다른 게시물을 만들었습니다. http://stackoverflow.com/questions/43322941/asp-net-core-http-500-error?noredirect=1#comment73711409_43322941 – Huby03

6

실제로 (ASP.NET Core 1.1) 수행하려는 작업에 대한 규칙이 포함 된 Rewrite라는 middleware이 있습니다.

당신은 다음과 같이 Startup.cs에 사용할 수

:

var options = new RewriteOptions() 
    .AddRedirectToHttpsPermanent(); 

app.UseRewriter(options); 
+0

여기에 몇 가지 추가 리소스가 있습니다 https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl –

관련 문제