I know in htaccess but how can I rewrite url of sitemap using web.config Rules property. I have tried following ways, but none worked
<rule name="sitemap URL" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^/sitemap.xml$" /> - Not working
<add input="{HTTP_HOST}" pattern="^domain.com/sitemap.xml$" /> - Not working
<add input="{HTTP_HOST}" pattern="^www.domain.com/sitemap.xml$" /> - Not working
</conditions>
<action type="Rewrite" url="foldername/sitemaps/sitemap-a.xml" />
</rule>
also tried
<rule name="sitemap URL" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^.+\.(local|www)?(domain).+\.(?:xml)$" />
<action type="Rewrite" url="foldername/sitemaps/sitemap-a.xml" />
</rule>
This worked for me.
<rule name="SiteMap" patternSyntax="Wildcard" stopProcessing="true">
<match url="sitemap.xml" />
<action type="Rewrite" url="sitemap.ashx" appendQueryString="false" />
</rule>
Related
My URL HTTP to HTTPS rewrite does not work when there is the character '&' in the URL.
A 410 page not found results.
An example that results in a 410 is...
http://curtainsmadesimple.co.uk/1062/Rapture-&-Wright/Rapture-&-Wright-Collection-Roomshots
OR
http://www.curtainsmadesimple.co.uk/1062/Rapture-&-Wright/Rapture-&-Wright-Collection-Roomshots
However if the '&' is replaced by 'and' in the above URLs the page loads correctly.
I have two rules to rewrite HTTP to HTTPS. One is where there is a non www and the other if there is a www
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.curtainsmadesimple\.co\.uk$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.curtainsmadesimple.co.uk/{R:1}" />
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Can anyone tell me why I am getting this issue?
Thanks in advance.
It will work I believe. This is working for me.
<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>
</rules>
I've a rewrite role in my web.config, and it's redirect to mydomain.com/de.
But now I will replace the action de/{R:1} with the user language, where I can get from {HTTP_ACCEPT_LANGUAGE}. But this is a string of language and looks like fr-CH,**fr**;q=0.8,en;q=0.6,de;q=0.4,de-CH;q=0.2/
So it's there possibility to get the out only the **fr** of this string?
Thanks for any help.
This is my role:
<rule name="mydomain.com" stopProcessing="true" >
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="/en/|/de/" negate="true" />
</conditions>
<action type="Redirect" url="de/{R:1}" />
</rule>
In the past i have used the following rule to redirect to a language based page
<rewrite>
<rules>
<rule name="RedirectToLang" enabled="true" stopProcessing="true">
<match url=".*" />
<action type="Redirect" url="{R:0}/{HTTP_ACCEPT_LANGUAGE}" appendQueryString="true" />
<conditions>
<add input="{HTTP_ACCEPT_LANGUAGE}" pattern=".+" />
</conditions>
</rule>
</rules>
</rewrite>
I tried but fail to do:
<rewrite>
<rules>
<rule name="blog url rewrite">
<match url="(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="mydomin.com/blog" />
<add input="{REQUEST_URI}" pattern="^mydomin/blog" />
</conditions>
<action type="Rewrite" url="cdn.mydomin.com/{C:1}" />
</rule>
</rules>
</rewrite>
Can anyone please help me? I have asp.net webform application 4.5
And I want to re-write: mydomain.com/blog to blog.mydomain.com
Try this:
<rules>
<rule name="blog url rewrite" stopProcessing="true">
<match url="blog" />
<action type="Redirect" url="/blog.{C:1}" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/(.*)/blog.*" />
</conditions>
</rule>
I want to redirect non-www and non-https URLs to https://www for my domain, I actually have the following in web.config, that works ok redirecting non-https to https but still allows to access domain.com without www,
<rewrite>
<rules>
<clear />
<rule name="Default to root" stopProcessing="true">
<match url="(.*)default.aspx" />
<action type="Redirect" url="{R:1}" />
</rule>
<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" />
</rule>
</rules>
</rewrite>
I have shared hosting..
This is a running code
<rewrite>
<rules>
<clear />
<rule name="Default to root" stopProcessing="true">
<match url="(.*)default.aspx" />
<action type="Redirect" url="{R:1}" />
</rule>
<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" />
</rule>
<rule name="Add www" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mydomain\.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Thanks #lexLi
I have found the following code which will redirect all my traffic to https:
<system.webServer>
<rewrite xdt:Transform="Insert">
<rules>
<rule name="RedirectToHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Is it possible to add an "exclusion" to this rule somehow?
I would like a particular path not to be redirected if possible
For example I would like everything below http://www.example.com/desktopmodules/ not to redirect.
Can it be done please?
You can add a rule above it which matches your exclusion pattern, ensuring that the stopProcessing="true" is set on the rule, but with no action:
<system.webServer>
<rewrite xdt:Transform="Insert">
<rules>
<!-- Prevent redirection of URLs matching this pattern -->
<rule name="ExcludeRedirectToHTTPS" stopProcessing="true">
<match url="^desktopmodules.*" />
<action type="None" />
</rule>
<rule name="RedirectToHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>