I am trying to create an URL Rewrite rule to send :
www.mycompany.com/file.aspx?someQueryString
or
www.mycompany.com/fileXYZ.aspx?someQueryString
to
www.subdomain.mycompany.com/file.aspx?someQueryString
or
www.subdomain.mycompany.com/fileXYZ.aspx?someQueryString
I wrote this rule:
<rule name="MyPageRewrite" stopProcessing="true">
<match url="(.*)(file[a-zA-Z]*\.aspx)" />
<action type="Rewrite" url="http://subdomain.mycompany.com/{R:1}" />
</rule>
The match expression seems to work, however the destination doesn't? What is wrong?
Thanks Lex Li, I did many tests with the test aspx file you provided and found a rule that works:
<rule name="MyPageRewrite" stopProcessing="true">
<match url="(.*)(file[a-zA-Z]*\.aspx)" />
<action type="Redirect" redirectType="Found" url="http://subdomain.mycompany.com/{R:0}" appendQueryString="true"/>
</rule>
Related
I just need to create a rule in my web config file to rewrite all URLs to given into rule
ex:
url/services/presentations-evenementielles to
url/Services/Presentations-Evenementielles
This is all made for SEO purposes to avoid duplicates.
<rule name="ProductionRule2" stopProcessing="true" patternSyntax="ExactMatch" >
<match url="^/productions/xyz" ignoreCase="true" />
<action type="Redirect" url="Productions/XYZ" redirectType="Permanent"/>
</rule>
Above code its gives me infinite loop error.
There was some mistakes with your rule
1.You were trying to use "^" in an exact match rule. Please set it to regular expression
2.You are trying to use "/" in match url. The match url part of domain/productions/xyz is
productions/xyz instead of /production/xyz.
3.You are enabling ignore case when you redirect URL to itself.
So please try to modify the rule like this
<rule name="ProductionRule2" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^productions/xyz" ignoreCase="false" />
<action type="Redirect" url="Productions/XYZ" redirectType="Permanent" />
</rule>
Update:
Please modify the rule like this
<rule name="ProductionRule2" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^Productions/XYZ" ignoreCase="false" negate="true" />
<action type="Redirect" url="Productions/XYZ" redirectType="Permanent" />
<conditions>
<add input="{ToLower:{URL}}" pattern="/productions/xyz" />
</conditions>
</rule>
And this is working on my side
Please remember to clean browser cache when you test the rule.And the URL should be prODuctions/Xyz instead of prODuction/Xyz.
attempting to re route
https://xxxxx.aaa.bb.cc.dd/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O
and
https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main_Rewrite.aspx?FOB=O
and
https://xxxxx.aaa.bb.cc.dd/net/prodmirror/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/net/prodmirror/FOB_Main_Rewrite.aspx?FOB=O
so retain everything before an aspx page and the query string. and replace it with a new aspx page. (replace only the filename and keep everything else)
here is my attempt.
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="^fob_main.aspx" />
<action type="Redirect" url="/FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule>
this is working fine for
https://xxxxx.aaa.bb.cc.dd/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O
but it is changing.
https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O
I also attempted
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="^fob_main.aspx" />
<action type="Redirect" url="{HTTP_HOST}/FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule>
but now I am getting
https://xxxxx.aaa.bb.cc.dd/testdev/xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O
I also attempted
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="(^.*)fob_main.aspx" />
<action type="Redirect" url="/{R:1}FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule>
but I am back to
https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O
(it is removing the testdev again)
interestingly using this rule
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="(^.*)fob_main.aspx" />
<action type="Redirect" url="/{R:1}FOB_Main_Rewrite.aspx" redirectType="Temporary" />
and directly typing into the browser
https://xxxxx.aaa.bb.cc.dd/testdev/testdev/FOB_Main.aspx?FOB=O
re routes me to the page I would like to go to.
https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main_Rewrite.aspx?FOB=O
This rule looks correct (if you placed this rule in root application):
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="(^.*)fob_main.aspx" />
<action type="Redirect" url="/{R:1}FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule>
This rule will work, if you placed it in sub application:
<rule name="Fob_Main_decommisioned" stopProcessing="true">
<match url="^fob_main.aspx" />
<action type="Redirect" url="FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule>
Most probably you back to https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O, because browser cached your wrong redirect before. Can you please do this steps:
Apply this rule
Clear cache in your browser
Try to open https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main.aspx?FOB=O
I'm not familiar with asp.net but need to add some redirects to the web.config. I added some examples of what I'm looking to match and my attempt of creating a rule:
<!--
URLs to match:
- example.com/parent-page
- example.com/parent-page/child
- example.com/parent-page/child/grandchild
-->
<rule name="parent-page/*" stopProcessing="true">
<match url="^parent-page/(.*)"/>
<action redirectType="Permanent" type="Redirect" url="/new-parent-page/{R:1}"/>
</rule>
I don't have the environment setup to test this at the moment so I'm wondering if this looks right?
I think this is the correct rule:
<rule name="parent-page/*" stopProcessing="true">
<match url="^parent-page(.*)"/>
<action type="Rewrite" url="new-parent-page{R:1}" appendQueryString="true"/>
</rule>
I'm trying to write a rules that match fr/Catalogue/?cf=jupes and redirect to vetements-femme/jupes/
I wrote the following rules :
<rule name="PapJupesSansGenre">
<match url="^fr\/Catalogue\/\?cf=jupes$"/>
<action type="Redirect" url="vetements-femme/jupes/"/>
</rule>
but it's not working. I guess the trouble is coming from the ? because if I try ^fr\/Catalogue\/cf=jupes$ it's working fine with fr/Catalogue/cf=jupes.
Any suggestions?
url doesn't include the querystring part, you should add a condition to match the url and the querystring.
The following rule should work :
<rule name="PapJupesSansGenre" >
<match url="^/fr/Catalogue/$" />
<conditions>
<add input="{QUERY_STRING}" pattern="cf=jupes" />
</conditions>
<action type="Redirect" url="vetements-femme/jupes/" appendQueryString="false"/>
</rule>
The appendQueryString attribute will indicate IIS not to vetements-femme/jupes/?cf=jupes
I have an url like this :
mydomain/page?param1=1
and I want rewrite this to :
mydomain/page2?param1=1
<rule name="MyRule" stopProcessing="true">
<match url="page?(.*)" />
<action type="Redirect" url="page2?{R:1}" />
</rule>
or
<rule name="MyRule" stopProcessing="true">
<match url="page\?(.*)" />
<action type="Redirect" url="page2?{R:1}" />
</rule>
This does not match, I do not understand why
The ? marks the start of the query string, which is not part of the path.
So if I follow, the rewriter wont even get to see the ? and anything past it.