Rename product page with web.config - asp.net

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?

Related

Force redirect to HTTPS

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>

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

IIS redirect rules for static content domains

I've written some rules for our static content subdomains so that, when they come into IIS, they are redirected to our www. subdomain.
The reason for this is that we have several subdomains being indexed by Google. However, when I create the urls, I am still able to view files at img1.mydomain.com with the statuscode being 200, rather than 301 as I would expect.
Am I doing something wrong?
<!-- Force img domains and non-www users to point at www. -->
<rule name="redirectImgJsAndNonWww" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^img1.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^img2.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^img3.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^js1.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^js2.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^js3.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^mydomain.com$" />
</conditions>
<action type="Redirect" url="www.mydomain.com/{R:0}" redirectType="Permanent" />
</rule>
Many thanks for any help.
Update: It appears that I was missing the logicalGrouping flag, which was setting my rules to "MatchAll".
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^img1.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^img2.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^img3.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^js1.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^js2.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^js3.mydomain.com$" />
</conditions>
<action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" />
</rule>
The question has now been answered.
It appears that I was missing the logicalGrouping flag, which was setting my rules to "MatchAll".
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^img1.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^img2.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^img3.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^js1.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^js2.mydomain.com$" />
<add input="{HTTP_HOST}" pattern="^js3.mydomain.com$" />
</conditions>
<action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" />
</rule>

Resources