I need help with the (number of) redirects on my website. At the moment I have 3 working redirects,
One goes from the WWW to the non www version. Another goes from the non SSL to https.
Finally I removed Server header to increase security.
They work but I think they are slowing my site down. Is there any way I can reduce the redirects to 2 ? I am looking for https://website.com
Here is my web.config:
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseExpires" httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" />
</staticContent>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Redirect to non-www" stopProcessing="true">
<match url="(.*)" negate="false"></match>
<action type="Redirect" url="http://website.com/{R:1}"></action>
<conditions>
<add input="{HTTP_HOST}" pattern="^website\.com$" negate="true"></add>
</conditions>
</rule>
</rules>
</rewrite>
<rewrite>
<outboundRules rewriteBeforeCache="true">
<rule name="Remove Server header">
<match serverVariable="RESPONSE_Server" pattern=".+" />
<action type="Rewrite" value="" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
I came up with something like this but it seems to have made it worse :
<rules>
<clear />
<rule name="Redirect www and non-https to https://">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^website\.com$" negate="true"></add>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
Here is my answer, I hope it can help someone with their SEO. I got redirects down from the highs of:
to a maximum of 1:
I just needed to add a s in one line and remove {HTTP_HOST} and instead put in the website name.
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://website.com{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Redirect to non-www" stopProcessing="true">
<match url="(.*)" negate="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^website\.com$" negate="true" />
</conditions>
<action type="Redirect" url="https://website.com/{R:1}" />
</rule>
</rules>
</rewrite>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.