Force redirect to HTTPS - asp.net

I need to force redirect to HTTPS in the following Trailing Slash RULE.
<rule name="Trailing Slash" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{URL}" pattern="WebResource.axd" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}/" redirectType="Permanent" />
</rule>
I need the end result to be of something below:
<rule name="Trailing Slash" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{URL}" pattern="WebResource.axd" negate="true" />
</conditions>
<action type="Redirect" url="https://www.somedomain.com/{R:1}/" redirectType="Permanent" />
</rule>

Related

How FIX choosing your permalink structure on WordPress for IIS server on Azure

Need your help.
There is one IIS server in Azure.
It contains the Website and the Angular SPA application.
I need to install in a separate directory WordPress blog.
Blog unfolded.
But there was a problem with Choosing your permalink structure.
I have an error:
403 - Forbidden: Access is denied.
Credentials that you are supplied with.
I have two web.config files
1. ROOT web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path=".">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="true" />
</authentication>
</security>
<rewrite>
<rules>
<clear />
<rule name="Redirect http to https" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" />
</rule>
<rule name="login redirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^login" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="ANGULAR-SPA-DIR/login" />
</rule>
<rule name="AngularJS Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="/ROOT-DIR/" ignoreCase="true" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="/ANGULAR-SPA-DIR/" ignoreCase="true" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="/TEST/" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
<rule name="AngularJS Routes1" stopProcessing="true">
<match url="^ANGULAR-SPA-DIR/" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/ANGULAR-SPA-DIR/index.html" />
</rule>
<rule name="AngularJS Routes2" stopProcessing="true">
<match url="^TEST/" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/TEST/index.html" />
</rule>
<rule name="WordPress Blog" stopProcessing="true">
<match url="blog/.*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
</conditions>
<action type="None" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
<caching>
<profiles>
<add extension=".css" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="00:30:00" />
<add extension=".svg" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="01:00:00" />
<add extension=".jpg" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="01:00:00" />
<add extension=".js" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="00:30:00" />
<add extension=".woff2" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="24.00:00:00" />
</profiles>
</caching>
<directoryBrowse enabled="true" />
</system.webServer>
</location>
</configuration>
Blog web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules><remove name="WordPress Blog"/>
<rule name="WordPress: https://ROOT-URL/blog" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule></rules>
</rewrite>
</system.webServer>
</configuration>
What can suggest experienced friends?
Add srting to ROOT web.config
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
...
<add input="{QUERY_STRING}" pattern="/blog/" />
</conditions>
After that, they "Choosing your permalink structure" work correctly

Rename product page with web.config

Since I have this URL:
http://namedomain.com/product.asp?id=01&color=05&name=xxxx
What is the better approach to rewrite this URL like this:
http://namedomain.com/xxxx
With IIS I was able to generate this URL
http://namedomain.com/01/05/xxxx
This is the web.config code:
<rule name="RedirecionaPagProduto" stopProcessing="true">
<match url="^exibe_produtos\.asp$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^produto=([^=&]+)&cor=([^=&]+)&url=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}/{C:3}" appendQueryString="false" />
</rule>
<rule name="RenamePagProduto" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="exibe_produtos.asp?produto={R:1}&cor={R:2}&url={R:2}" />
</rule>
Anyone can help?

URL Rewriting with Query Strings using IIS URL Rewrite Module

I am trying to rewrite a url such as:
new_membership?R=1&I=2
to:
agent_new_membership.aspx?R=1&I=2
but I am getting an error reading: "HTTP Error 404.0 - Not Found"
This is the web.config code I am using:
<rewrite>
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/administration" value="/administration_main.aspx" />
<add key="/change_admin_password" value="/admin_change_password.aspx" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="New Membership" stopProcessing="true">
<match url="^new_membership?R=(\d+)&I=(\d+)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="agent_new_membership.aspx?R={R:1}&I={R:2}" />
</rule>
<rule name="Redirect rule1 for Redirects">
<match url=".*" />
<conditions>
<add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
What am I doing wrong?
Thanks in advance.
This should work for you:
<rule name="TestRule" stopProcessing="true">
<match url="^new_membership\?R=(\d+)&I=(\d+)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="agent_new_membership.aspx?R={R:1}&I={R:2}" />
</rule>

Rewrite IIS URL to Point at Subfolder for Wordpress

I've got three installations of Wordpress on the same server, and they're with the following layout:
Site1
Site1\Site2
Site1\Site3
I have four URLS www.site1.com, www.site2.co.uk, www.site2.com and www.site3.co.uk. I'd like to set up URL rewriting in a web.config file so that the URLs point to their corresponding folders. Also I need the Wordpress installations to use Permalinks.
This is my set up (completely not working) at the moment:
<rule name="site1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<action type="Rewrite" url="index.php"/>
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
<add input="{HTTP_HOST}" matchType="Pattern" pattern="*www.site2.co*" ignoreCase="true" negate="true"/>
<add input="{HTTP_HOST}" matchType="Pattern" pattern="*www.site3.co*" ignoreCase="true" negate="true"/>
<add input="{PATH_INFO}" pattern="*site2*" negate="true"/>
<add input="{PATH_INFO}" pattern="*site3*" negate="true"/>
</conditions>
</rule>v
<rule name="site2" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<action type="Rewrite" url="site2/index.php"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{HTTP_HOST}" matchType="Pattern" pattern="*www.site2.co*" ignoreCase="true" negate="false"/>
<add input="{PATH_INFO}" pattern="*site2*" ignoreCase="true" negate="false"/>
<add input="{PATH_INFO}" pattern="*wp-admin*" negate="true"/>
<add input="{PATH_INFO}" pattern="*wp-content*" negate="true"/>
<add input="{PATH_INFO}" pattern="*wp-login*" negate="true"/>
</conditions>
</rule>
<rule name="site2-content" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<action type="Rewrite" url="site2/{R:0}"/>
<conditions>
<add input="{HTTP_HOST}" pattern="*www.site2.co*"/>
<add input="{PATH_INFO}" pattern="*wp-content*"/>
</conditions>
</rule>
<rule name="site2-admin" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<action type="Rewrite" url="site2/{R:0}"/>
<conditions>
<add input="{HTTP_HOST}" pattern="*www.site2.co*"/>
<add input="{PATH_INFO}" pattern="*wp-admin*"/>
</conditions>
</rule>
<rule name="site2-login" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<action type="Rewrite" url="site2/{R:0}"/>
<conditions>
<add input="{HTTP_HOST}" pattern="*www.site2.co*"/>
<add input="{PATH_INFO}" pattern="*wp-login*"/>
</conditions>
</rule>
<rule name="site3" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<action type="Rewrite" url="site3/index.php"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{HTTP_HOST}" matchType="Pattern" pattern="*www.site3.co*" ignoreCase="true" negate="false"/>
<add input="{PATH_INFO}" pattern="*site3*" ignoreCase="true" negate="false"/>
<add input="{PATH_INFO}" pattern="*wp-admin*" negate="true"/>
<add input="{PATH_INFO}" pattern="*wp-content*" negate="true"/>
<add input="{PATH_INFO}" pattern="*wp-login*" negate="true"/>
</conditions>
</rule>
<rule name="site3-content" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<action type="Rewrite" url="site3/{R:0}"/>
<conditions>
<add input="{HTTP_HOST}" pattern="*www.site3.co*"/>
<add input="{PATH_INFO}" pattern="*wp-content*"/>
</conditions>
</rule>
<rule name="site3-admin" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<action type="Rewrite" url="site3/{R:0}"/>
<conditions>
<add input="{HTTP_HOST}" pattern="*www.site3.co*"/>
<add input="{PATH_INFO}" pattern="*wp-admin*"/>
</conditions>
</rule>
<rule name="site3-login" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<action type="Rewrite" url="site3/{R:0}"/>
<conditions>
<add input="{HTTP_HOST}" pattern="*www.site3.co*"/>
<add input="{PATH_INFO}" pattern="*wp-login*"/>
</conditions>
</rule>
<rule name="wordpress" patternSyntax="Wildcard" stopProcessing="true">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>
Any help much appreciated.

ASP.NET Web.config issue with MagicAjax and Rewrite Rules

Hey, I have the following rules in webconfig for my ASP.NET website which also contains several sections which are controlled in wordpress.
<rules>
<rule name="RedirectFinancial" stopProcessing="true">
<match url="^orgprofile/financial\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^name=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/financial" appendQueryString="false" />
</rule>
<rule name="RewriteFinancial" stopProcessing="true">
<match url="^([^/]+)/financial/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="orgprofile/financial.aspx?name={R:1}" />
</rule>
<rule name="RedirectGovernance" stopProcessing="true">
<match url="^orgprofile/governance\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/governance" appendQueryString="false" />
</rule>
<rule name="RewriteGovernance" stopProcessing="true">
<match url="^([^/]+)/governance/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="orgprofile/governance.aspx?name={R:1}" />
</rule>
<rule name="RedirectOverview" stopProcessing="true">
<match url="^orgprofile/overv\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^name=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteOverview" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="orgprofile/overv.aspx?name={R:1}" />
</rule>
<rule name="RedirectPurpose" stopProcessing="true">
<match url="^orgprofile/purpose\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^name=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/purpose" appendQueryString="false" />
</rule>
<rule name="RewritePurpose" stopProcessing="true">
<match url="^([^/]+)/purpose/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="orgprofile/purpose.aspx?name={R:1}" />
</rule>
<rule name="RedirectActivities" stopProcessing="true">
<match url="^orgprofile/activities\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^name=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/activities" appendQueryString="false" />
</rule>
<rule name="RewriteActivities" stopProcessing="true">
<match url="^([^/]+)/activities/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="orgprofile/activities.aspx?name={R:1}" />
</rule>
<rule name="RewriteWordPress" patternSyntax="ECMAScript">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="\.axd$" negate="true" />
<add input="{URL}" pattern="view.aspx$" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^([^/]+)/financial/?$" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^([^/]+)/governance/?$" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^([^/]+)/?$" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^([^/]+)/purpose/?$" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="^([^/]+)/activities/?$" negate="true" />
</conditions>
<serverVariables />
<action type="Rewrite" url="index.php" />
</rule>
The problem with magicajax when I add the above Rules is that my magicajax uploader doesnt work as intended anymore and when I click on the upload button it causes a page refresh where as before it would come up automatic.
Any Ideas how I can get around this ?
EDIT : The problem seems to be overview rewrite rule
My friendly urls look like this
http://hostname/foldername/companyname <--- overview
http://hostname/foldername/companyname/purpose <---- i.e purpose rewrite rule

Resources