I have the following rewrite rule.
<rule name="cheapbastardz.signupcode" stopProcessing="true">
<match url="^signup/code/([_0-9a-z-%=\+\$]*)$" />
<conditions>
</conditions>
<action type="Rewrite" url="Page.aspx?sc={R:1}" appendQueryString="false" />
</rule>
Now when the user click on a buton where the page is posted back the url changes from
http://localhost/CBAanmelding/signup/code/3f69fa28-5c6c-4815-a2b3-3c846651bed9
to
http://localhost/CBAanmelding/signup/code/3f69fa28-5c6c-4815-a2b3-3c846651bed9?sc=3f69fa28-5c6c-4815-a2b3-3c846651bed9
I don't want the querystring to appear. How can I prevent this. Thanks in advance.
Gr
Martijn
Are you sure your rule is firing?
The match pattern does not seem to fit the incoming URL. The incoming URL begins with /CBAanmelding, while your pattern looks for URLs that bbegin with signup. The circumflex preceding the word signup is a zero-width assertion that the pattern matches only at the beginning of the URL.
Maybe you need to change the pattern?
<rule name="cheapbastardz.signupcode" stopProcessing="true">
<match url="^CBAanmelding/signup/code/([_0-9a-z-%=\+\$]*)$" />
<conditions>
</conditions>
<action type="Rewrite" url="Page.aspx?sc={R:1}" appendQueryString="false" />
</rule>
use
form1.Action = Request.RawUrl;
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.
Here is my web.config rule
<rule name="spiderRedirect" stopProcessing="true">
<match url=".post/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z-]+)" />
<action type="Redirect" url="https://example.net/bot/post.php?category={toLower:{R:1}}&id={toLower:{R:2}}&title={toLower:{R:3}}" appendQueryString="false" />
</rule>
This should give this result
input:
https://example.net/post/celebrity/4cHYQ7i/maisie-williams
should result in:
{R1}: celebrity
{R2}: 4cHYQ7i
{R3}: maisie-williams
and it should redirect to:
https://example.net/bot/post.php?category=celebrity&id=4cHYQ7i&title=maisie-williams
This input:
https://example.net/post/nerdy/NE5cHQZ/when-i-have-to-do-technical-support
should result in:
{R1}: nerdy
{R2}: NE5cHQZ
{R3}: when-i-have-to-do-technical-support
The server runs and I am quite sure the regex is correct, but the rule is never triggered. I am never redirected to google, even if I use the above input.
Why isn't the rule triggered?
I got it working. Also with check for User agent.
I use this to redirect web crawlers.
<rule name="spiderRedirect" stopProcessing="true">
<match url=".?post/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z-]+)" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="(Google|MSNBot|Twitterbot|Pinterest|Facebot|facebookexternalhit|MJ12bot|bingbot|SimplePie|SiteLockSpider|okhttp|curl|YandexBot|ScoutJet|Slurp|DuckDuckBot|Baiduspider|Sogou|Konqueror|Exabot|ia_archiver|Screaming)"/>
<add input="{HTTPS}" pattern="on"/>
</conditions>
<action type="Redirect" url="https://example.net/bot/post.php?category={toLower:{R:1}}&id={toLower:{R:2}}&title={toLower:{R:3}}" appendQueryString="false" />
</rule>
You will escape "/" to matching your different input. The new regex is :
([0-9a-zA-Z]+)\/([0-9a-zA-Z]+)\/([0-9a-zA-Z-]+)
You can test it on https://regex101.com.
It match for your two different input.
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 a rule in url rewrite module like below
<rule name="articleSectionUrl">
<match url="(.+)/([0-9]+)/(.+)/([0-9]+)" />
<action type="Rewrite" url="article.aspx?articleid={R:4}" appendQueryString="false" />
</rule>
It works properly as it detects below type of article url's:
http://www.emusician.com/news/0766/spl-launches-usb-and-madi-interfaces/151461
That's fine, but it also detects below type of url, which is the image path unfortunately:
http://www.emusician.com/Portals/9/SlideShowThumbnails/15/ad300x250_02.gif
Can anyone tell me how can i avoid this.
Thanks all, #Aquillo as per your regex it will just limit the file whose extension I provide in the regex, that means I always have to provide the extensions in the regex for the url I want to ignore, so here's the complete solution to my problem.
UrlRewrite module has a <conditions> element under <rule> with this we limit any type of file which comes in the url.
Here's the complete solution:
<rule name="articleSectionUrl">
<match url="(.+)/([0-9]+)/(.+)/([0-9]+)" />
<action type="Rewrite" url="article.aspx?articleid={R:4}" appendQueryString="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
</rule>
Thanks guys for helping me.
I have read the threads and I still can't work it out, my problem I know, but wondering if could point me in the right direction.
I have setup a rule:
www.mydomain.com/productlist.asp?CategoryID=2
rewritten to
www.mydomain.com/homeware/cushions
.
<rule name="cushions">
<match url="^homeware/cushions" />
<action type="Rewrite" url="productlist.asp?CategoryID=2" />
</rule>
ok, now my problem is with pagination of the results, so the original domain when the user goes onto the next page would look like:
www.mydomain.com/productlist.asp?CategoryID=2&Page=2
This is where I'm having problems - I want this to become:
www.mydomain.com/homeware/cushions?page=2
and ongoing for how many pages
just can't get it to work - I understand I need to use query string but really struggling. Asking for expertise, thanks for any help
To capture the Query String you need to use conditions for that since the match URL does not include it.
So you could do that with a rule like:
<rule name="cushions" stopProcessing="true">
<match url="^homeware/cushions$" />
<conditions>
<add input="{QUERY_STRING}" pattern="page=(\d+)" />
</conditions>
<action type="Rewrite" url="productlist.asp?CategoryID=2&page={C:1}" appendQueryString="false" />
Just add appendQueryString="true" in action will automatically append query string.
<rewrite>
<rules>
<rule name="test">
<match url="^homeware/cushions" />
<action type="Rewrite" url="/test/test.cfm?category=5" appendQueryString="true" />
<conditions>
</conditions>
</rule>
</rules>
</rewrite>
http://localhost:8081/homeware/cushions?page=2
You will receive page in URL variable with value 2.