Home IIS.NET Forums IIS 7 and Above General URL Rewrite to redirect ONLY .html pages
Last post Sep 20, 2019 01:13 PM by steve841
5 Posts
Sep 19, 2019 03:26 PM|steve841|LINK
OK ..I've used the common URL rewrite to redirect http to https.
Problem I'm seeing: Google crawls for sitemaps.xml and ads.txt and isn't happy.
Can someone help me with the http to https redirect for HMTL pages only so the .xml and .txt are ignored?
URL rewrite is Definitely my weakness.
IIS 7 / Thanks. Working/existing rule below.
</rule> <rule name="https" enabled="true" patternSyntax="Wildcard" stopProcessing="true"> <match url="*" /> <conditions logicalGrouping="MatchAny"> <add input="{HTTPS}" pattern="www.123.com" /> </conditions> <action type="Redirect" url="https://www.123.com/{R:1}" redirectType="Permanent" /> </rule>
1596 Posts
Sep 20, 2019 03:26 AM|Jalpa Panchal|LINK
Hi,
You could use below url rewrite rule:
<rule name="HTTPS force" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" /> <add input="{HTTP_HOST}" pattern="^www.abc.com$" /> <add input="{REQUEST_URI}" pattern="(.*)\.html|(.*)\.html|(.*)" /> <add input="{REQUEST_URI}" pattern="(.*)\.txt|(.*)\.xml" negate="true" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" /> </rule>
in https you can only use on or off.
to match the hostname you need to use {http_host} server variable.
<add input="{REQUEST_URI}" pattern="(.*)\.txt|(.*)\.xml" negate="true" /> this rule deny the txt and xml file to redirect http to https.
<add input="{REQUEST_URI}" pattern="(.*)\.html|(.*)\.html|(.*)" /> this rule allow html ,htm and other extetion page to redirect http tp https.
You could refer this below document for more detail:
IIS Server Variables
URL Rewrite Module Configuration Reference
Creating Rewrite Rules for the URL Rewrite Module
Regards,
Jalpa
Sep 20, 2019 01:13 PM|steve841|LINK
Awesome! Thanks.
I'll give it some testing.
5 Posts
URL Rewrite to redirect ONLY .html pages
Sep 19, 2019 03:26 PM|steve841|LINK
OK ..I've used the common URL rewrite to redirect http to https.
Problem I'm seeing: Google crawls for sitemaps.xml and ads.txt and isn't happy.
Can someone help me with the http to https redirect for HMTL pages only so the .xml and .txt are ignored?
URL rewrite is Definitely my weakness.
IIS 7 / Thanks. Working/existing rule below.
1596 Posts
Re: URL Rewrite to redirect ONLY .html pages
Sep 20, 2019 03:26 AM|Jalpa Panchal|LINK
Hi,
You could use below url rewrite rule:
in https you can only use on or off.
to match the hostname you need to use {http_host} server variable.
<add input="{REQUEST_URI}" pattern="(.*)\.txt|(.*)\.xml" negate="true" /> this rule deny the txt and xml file to redirect http to https.
<add input="{REQUEST_URI}" pattern="(.*)\.html|(.*)\.html|(.*)" /> this rule allow html ,htm and other extetion page to redirect http tp https.
You could refer this below document for more detail:
IIS Server Variables
URL Rewrite Module Configuration Reference
Creating Rewrite Rules for the URL Rewrite Module
Regards,
Jalpa
5 Posts
Re: URL Rewrite to redirect ONLY .html pages
Sep 20, 2019 01:13 PM|steve841|LINK
Awesome! Thanks.
I'll give it some testing.