MVC URL Redirect www to non-www

IIS panelinden Site Bindings kısmından servera hem www.siteadi.com hemde sadece siteadi.com şekilde giriş yapıldığından emin olun.

Şimdi öncelikle serverınıza bu eklentiyi kurmalısınız.

https://www.iis.net/downloads/microsoft/url-rewrite

Daha sonra Web.config dosyanıza bu satırları eklemelisiniz. Ekleme yapıtığınızda Modülün içinde bu kurallar otomatik olarak görünecektir.

<system.webServer>
<rewrite>
<rules>

<rule name=”Redirect to non-www” stopProcessing=”true”>
<match url=”(.*)” negate=”false”></match>
<conditions>
<add input=”{HTTP_HOST}” pattern=”^siteadi\.com$” negate=”true”></add>
</conditions>
<action type=”Redirect” url=”https://siteadi.com/{R:1}”></action>
</rule>

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

Eğer https yönlendirmeyi de dahil etmek isterseniz.

<system.webServer>
<rewrite>
<rules>

<rule name=”Redirect to non-www” stopProcessing=”true”>
<match url=”(.*)” negate=”false”></match>
<conditions>
<add input=”{HTTP_HOST}” pattern=”^siteadi\.com$” negate=”true”></add>
</conditions>
<action type=”Redirect” url=”https://siteadi.com/{R:1}”></action>
</rule>

<rule name=”HTTP to HTTPS redirect” stopProcessing=”true”>
<match url=”(.*)” />
<conditions>
<add input=”{HTTPS}” pattern=”off” ignoreCase=”true” />
</conditions>
<action type=”Redirect” redirectType=”Permanent” url=”https://{HTTP_HOST}/{R:1}” />
</rule>

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