I need to check thru URL rewrite if the URL has question mark after 'search-product-list/'. I'm using tuckey. Here's the current rule:
<rule>
<from>^/n/search-product-list/(.*)$</from>
<to last="true" type="permanent-redirect">/ttsvr/search-product-list/$1</to>
</rule>
<rule>
<from>^/search-product-list/(.*)$</from>
<to last="true" type="forward">/n/force-redirect/fitmycar-webdesign-73?query=$1</to>
</rule>
i was able to get the result I expected by doing this:
<rule>
<from>^/search-product-list/(.*)?q(.*)$</from>
<to last="true" type="forward">/n/force-redirect/fitmycar-webdesign-73?query=$1</to>
</rule>
Related
I want to rewrite my URL Querystring in IIS i.e to update my ip=0
so I tried to regex like this
Actual URL
http://test.com/track/?ip=1&_=12345
Expected result
http://api.com/track/?ip=0&_=12345
MY Regex
http://test.com/([_0-9a-z-]+)/([?_0-9a-z]+)=([0-9]+)(.*)
http://api.com/{R:1}/{R:2}=0{R:4}
Can you please help me?
For the different web site, Redirect is a preferable way to Url Rewrite. Otherwise, Rewrite is applicable to the same web site.
https://blogs.iis.net/owscott/url-rewrite-vs-redirect-what-s-the-difference
We need to match the query string, and then we can assign the fragment of the query string to the new action.
ip=([0-9]+)&_=([0-9]+)
Please refer to the below screenshot.
WebConfig.
<rewrite>
<rules>
<rule name="MyRule" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="ip=([0-9]+)&_=([0-9]+)" />
</conditions>
<action type="Redirect" url="http://localhost/track?ip=0&_={C:2}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
Here is a related discussion.
https://forums.iis.net/t/1238891.aspx?Url+Rewrite+with+multiple+querystring+
I have a server with three websites:
Default website, port 80 (no content)
Website A, port 81
Website B, port 82
I would like to use URL Rewrite to access Website A and Website B like:
http://myserver/A
http://myserver/B
instead of
http://myserver:81
http://myserver:82
I have installed the URL Rewrite and Application Request Routing modules and enabled the proxy for ARR.
On the default website I created two rewrite rules using the regex pattern /A/(.*) and /B/(.*):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WebsiteA" stopProcessing="true">
<match url="/A/(.*)" />
<action type="Rewrite" url="http://localhost:81/{R:1}" />
</rule>
<rule name="WebsiteB" stopProcessing="true">
<match url="/B/(.*)" />
<action type="Rewrite" url="http://localhost:82/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Using the Test pattern... functionality I could verify that {R:0} contained the entire test URL and {R:1} just the part after A/ or B/. The rewrite URL I sat to point to either port 81 or 82. I still regard regular expressions as pure magic but the test gave me what I wanted. Trying to connect to the websites through /A/ and /B/ gave me 404 errors.
Seeing that this is a very common problem with lots of questions and answers I picked one suggesting to use the regex pattern ^A(.*)$:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WebsiteA" stopProcessing="true">
<match url="^A(.*)$" />
<action type="Rewrite" url="http://localhost:81/{R:1}" />
</rule>
<rule name="WebsiteB" stopProcessing="true">
<match url="^B(.*)$" />
<action type="Rewrite" url="http://localhost:82/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Using the test functionality my test URLs failed to match that pattern, but when I tried to access the sites using the new pattern, it worked.
Question: I am going with the later solution but is it pure luck that it works and should I perhaps do something different?
Is it normal for the test functionality to not successfully match the same URL's that works when I feed them to the server?
I have the following rule...
<rule>
<condition type="scheme" operator="equal">^http$</condition>
<from>/(.*)</from>
<to type="temporary-redirect" last="true">https://something.com/$1</to>
</rule>
... And it works just fine (gives a 302 redirect) however i want to make it 307 redirect since that preserves parameters. I tried the following and have had no luck:...
<rule>
<condition type="scheme" operator="equal">^http$</condition>
<from>/(.*)</from>
<set type="status">307</set>
<to type="temporary-redirect" last="true">https://something.com/$1</to>
</rule>
Any idea how to do this?
Figured it out!... You have to set the location header manually. Also null out the "to" node.
<rule>
<condition type="scheme" operator="equal">^http$</condition>
<from>/(.*)</from>
<set type="status">307</set>
<set type="response-header" name="Location">https://something.com/$1</set>
<to last="true">null</to>
</rule>
I have the following rule in my webconfig
<rule name="accommidationRewrite2" enabled="true" stopProcessing="true">
<match url="accommodation/(?!results|!property).*?(.*)/" />
<action type="Rewrite" url="/index.cfm/?path=/accommodation/results/params/location/{R:1}/" />
</rule>
I'm trying to get the rule to kick in is the URL is not 'accommodation/results/....' OR 'accommodation/property/.....'
At the moment it only work for the results URL. Can I get it to work for both URL's?
Remove the ! symbol which was present before the property ,
accommodation/(?!results|property).*?(.*)/
I'm using Tuckey to remove the URL .xhtml extension with the following rules:
<rule>
<from>^/?([a-z-]+)/$</from>
<to>/$1.xhtml</to>
</rule>
<rule>
<from>^/?([a-z-]+)$</from>
<to>/$1.xhtml</to>
</rule>
So /page/ and /page gets mapped to /page.xthml
However, if I have /directory/page/ this doesn't map to /directory/page.xhtml.
<rule>
<from>^/?([a-z-/]+)/$</from>
<to>/$1.xhtml</to>
</rule>
<rule>
<from>^/?([a-z-/]+)$</from>
<to>/$1.xhtml</to>
</rule>
I added the slash into the list of repeatable characters and this worked
use this rule :
<rule>
<from>^/?[a-z-]*?/?([a-z-]+)/$</from>
<to>/$1.xhtml</to>
</rule>
<rule>
<from>^/?[a-z-]*?/?([a-z-]+)$</from>
<to>/$1.xhtml</to>
</rule>