From https://gist.github.com/stevensk/c8108311b82ba1591cb1be018bbe0119, I have added the code below to our web.config for "site maintenance page redirect".
For an IP that isn't mine (mine is 3rd item down in IP list), the user is directed to the site maintenance page, but it hasn't been displaying the background image, specified fonts, or other CSS file styles.
The Firefox inspector shows the following message in red:
The resource from
“https://www.example.com/pages/maintenance/message/default.htm”
was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
How can I get the maintenance page to have the correct fonts, images and other styles applied?
<rewrite>
<!-- Maintenance rewrite map
- Add allowed IP addresses to grant access during maintenance period
- To activate, uncomment Maintenance Redirect rule
- And replace last key with current IP found at /pages/test/remote-name/
-->
<rewriteMaps>
<rewriteMap name="MaintenanceIpAddressWhitelist" defaultValue="">
<add key="192.168.0.1" value="1" />
<add key="127.0.0.1" value="1" />
<add key="198.43.70.125" value="1"/>
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
<rule name="ensurewww" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" />
</conditions>
<action type="Redirect" url="{C:1}://www.{C:2}" redirectType="Permanent" />
</rule>
<!-- Maintenance Rule -->
<rule name="Maintenance Redirect">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{MaintenanceIpAddressWhitelist:{REMOTE_ADDR}}" matchType="Pattern" pattern="1" negate="true" />
<add input="{REQUEST_URI}" pattern="^/pages/maintenance/message/default.htm$" negate="true" />
</conditions>
<action type="Redirect" url="/pages/maintenance/message/default.htm" appendQueryString="false" redirectType="Temporary"/>
</rule>
</rules>
</rewrite>
I ended up embedding images, css, svg and font files as base64 into the default.htm page.
Related
I want to rewrite this URL
https://www.website.com/parameter-1?query=100345046
To this
https://www.website.com/parameter?query=100345046
Basically I want the -1 removed from the URL.
I made an example which works, using RegExr, but I don't know how to implement this using the IIS.
So far I made this rule but I can't get the query part after the -1 to stick the to rewrote URL.
<rule name="Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="^/parameter-1$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/parameter" appendQueryString="true" />
</rule>
Alright I figured it out.
<rule name="Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="/parameter-1\?query=(.*)$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/parameter?" appendQueryString="true" redirectType="Permanent" />
</rule>
Our site https://www.globalcompanyformation.co.uk/ has a redirect to "https://" in the web.config file for all urls .
Now we have a form which sends information to our subdomain which is hosted in another ip address and which is not secure . This form is in our page https://www.globalcompanyformation.co.uk/Gcf-index.html . Firefox gives a warning message that the site to which you are redirected is not secure . We dont want to see this alert and when i checked whole internet the only solution was that i get the page "Gcf-index.html" to have "http" and not "https" .
Is there any way that i could force Gcf-index.html to open in "http" . The web.config coding is as follows as of now for redirecting to https for all urls .
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{REQUEST_FILENAME}" negate="true" pattern="^Gcf-index.*" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
Change the second condition to
<add input="{REQUEST_FILENAME}" negate="true" pattern="Gcf-index\.html" />
Add the following rule to force http on that form page.
<rule name="Force http on GCF" stopProcessing="true">
<match url="Gcf-index\.html$" />
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}"
redirectType="Permanent" appendQueryString="false" />
</rule>
I read that .htaccess doesn't work on windows server like godaddy. So to hide or remove extensions like .php and .html on URL, you can accomplish this by creating a web.config file with the following code:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteHTML">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions> <action type="Rewrite" url="{R:1}.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I tried to make web.config file and save it where index.php is with that code but nothing happened.. I tested it with the like this
<ul>
<li>
Attack on Titan Episode 3
</li>
</ul> with a href of "attackontitan-3"
I want url to be http://mysite/watching/attack%20on%20titan/attackontitan-3 not http://mysite/watching/attack%20on%20titan/attackontitan-3.php
Use rewrite to add the extension, like this:
<rule name="rewritephp">
<!--Removes the .aspx extension for all pages.-->
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
Or This tutorial does a great job at explaining what you need to do with IIS.
http://atlantawebsites.blogspot.com/2010/06/vanity-urls-with-godaddy-hosting-using.html
You need to add a Rewrite and Redirect rules. The following will redirect and rewrite page.php to just page. If you want to do the same for html, just add those rules.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!-- Remove the existing rules just incase we already defined them -->
<remove name="RedirectPhpExtensions" />
<remove name="RewritePhpExtensions" />
<!-- Add a rule to redirect x.php pages to just x -->
<rule name="RedirectPhpExtensions" enabled="true" stopProcessing="true">
<match url="(.*)\.php$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<!-- Add a rule to rewrite the x pages to x.php behind the scene -->
<rule name="RewritePhpExtensions" enabled="true" stopProcessing="true">
<match url="(.*)" negate="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Place this web.config in the root directory of your domain.
Then you need to restart the Application Pool on godaddy's site:
Web Hosting > Manage > IIS Management > Recycle App Pool button
I have a new site https://www.NewSite.com and I would like all the traffic to my old site https://www.OldSite.com to be redirected to the root of my new site https://www.NewSite.com/, with some exception.
For instance I would like the URL (among others) https://www.OldSite.com/noredirect not to be redirected and others to be rewritten. For instance:
https://www.OldSite.com -> https://www.NewSite.com/
https://www.OldSite.com/library->https://www.NewSite.com/
https://www.OldSite.com/kb/ -> https://www.newsite.com/kb
https://www.OldSite.com/kb/articles.aspx?id=45 -> https://www.NewSite.com/kb
https://www.OldSite.com/noredirect -> https://www.oldsite.com/noredirect
https://www.OldSite.com/noredirect/page.aspx -> https://www.oldsite.com/noredirect/page.aspx
Therefore I wrote two rules in my Old Site site in IIS:
<rewrite>
<rules>
<clear />
<rule name="Rewrite To New Site" stopProcessing="true">
<match url="/kb(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="https://www.newsite.com/kb" />
</rule>
<rule name="Redirect to New Site" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="(.*)/noredirect$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.newsite.com" appendQueryString="false" />
</rule>
</rules>
</rewrite>
This rules just redirect all the requests to my old site to the root of my new site, ignoring the exceptions and the rewrite rule. The same happens with:
<rule name="Redirect to New Site" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="^/noredirect(.*)" negate="true" />
</conditions>
<action type="Redirect" url="https://www.newsite.com" appendQueryString="false" />
</rule>
What am I doing wrong?
Make sure you've checked "Enable proxy" under Application Request Routing cache.
You can find some information about it here:
http://www.iis.net/learn/extensions/configuring-application-request-routing-%28arr%29/creating-a-forward-proxy-using-application-request-routing
Good luck!
I am trying to rewrite a html response with an outboundrule, but it is not working: This are my inbound and outbound rules:
<rules>
<rule name="IE56 Do not gzip js and css" stopProcessing="false">
<match url="\.(css|js|emz|jpg|htm|html)" />
<action type="None" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
<rule name="Route the requests for eserver" patternSyntax="ECMAScript">
<match url="^eServer/(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://mckyesvr/eServer/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame,Img, Input, Link, Script" pattern="^http(s)?://mckyesvr/eServer/(.*)" ignoreCase="true" />
<conditions>
<add input="{URL}" pattern="/PageLoader" negate="true" />
</conditions>
<action type="Rewrite" value="/eServer/{R:2}" />
</rule>
<rule name="ReverseProxyOutboundRule8" preCondition="ResponseIsHtml1">
<match pattern="http://mckyesvr/eServer/PageLoader.asp?Page=Process_Safety.dsp"/>
<action type="Rewrite" value="/eServer/PageLoader.asp?Page=Process_Safety.dsp" />
</rule>
They work perfectly with almost every HTML response except with the ones that have this HTML reponses form:
"<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
.......etc and this is the part that I want to rewrite:
<_a href="http://mckyesvr/eServer/PageLoader.asp?Page=Process_Safety.dsp"
target="_parent">Go Back to Process Safety------
I have tried changing the compressing, change the outbound rules, move a thousand parameters but nothing has worked out until now, I don't know why this is happening just with an HTML response as the one indicated above, it looks like it is coded because Outboundrules don't catch it.