webforms ASP.Net project ApportRequest http 1.0 ,1.1 - http

I tried to add a rewrite to the web. config file
<rewrite>
<rules>
<rule name="RequestBlockingRule1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{SERVER_PROTOCOL}" pattern="HTTP/1.0" />
</conditions>
<action type="AbortRequest" />
</rule>
<rule name="RequestBlockingRule11" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{SERVER_PROTOCOL}" pattern="HTTP/1.1" />
</conditions>
<action type="AbortRequest" />
</rule>
</rules>
</rewrite>
but when I run it gave me site can't be reached
any one know how this can be done in a webforms project ASP.Net

Related

How to re-write subdirectory to subdomain

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>

Redirection from "https://www" to "https://"

We have the ASP.NET application hosted as Azure WebApp and configured the domain from GoDaddy. We bought SSL for non-www domain. We used the following redirection rule:
<rewrite>
<rules>
<rule name="Redirect to Example.com">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!^Example.com)" />
</conditions>
<action type="Redirect" url="https://Example.com/{R:1}"/>
</rule>
<rule name="Redirect to https">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="Off"/>
<add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
</rewrite>
Is there a way to add another rule to redirect request to "https://www" to "https://"?
Thanks,
Jay
I had a similar challenge with my Windows hosting since I have a wildcard cert and host a few subdomains. Here's the web.config I put together, give it a shot and let me know! It seems to work great for me, but my site is extremely simple.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<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="remove www" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.YourDomain\.com$" />
</conditions>
<action type="Redirect" url="https://YourDomain.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

force website http:// to https://www asp.net

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

Rewriting sitemap.xml url - asp.net web.config

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>

IIS Api redirect rule

I need some help with a redirect regex in my web.config. I have a website UI and an App UI which hit the same serverside API but I'm decoupling the urls that get called from either for future-proofing the app against API updates.
This is what I have so far in my web.config and it works for redirecting api.mywebsite.com to mywebsite.com, but how do I write the regex to add the version at the end so that http://api.mywebsite.com/v1/ gets redirected to http://www.mywebsite.com ?
<rules>
<rule name="Remove WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(api\.)(.*)$" />
</conditions>
<action type="Redirect" url="http://dev.blahblah.org.au{PATH_INFO}" redirectType="Permanent" />
</rule>
</rules>
<rule name="Remove WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(api\.)(.*)$" />
<add input="{PATH_INFO}" pattern="^/v(\d+)/(.*)$" />
</conditions>
<action type="Redirect" url="http://localhost{PATH_INFO}?v={C:1}" redirectType="Permanent" />
</rule>

Resources