I have a need to rewrite a url for an invoice that has a "#" in the querystring. Evidently the "#" is causing IIS to balk somehow. The rule I have currently is:
^invoice/([_0-9a-z-#]+)
and the action is:
invoice.aspx?id={R:1}
Pretty simple and works fine so long as there's no "#" in the invoice number. Is there any way to include this so it works?
Hash Tags in the URL serve a special purpose to the client browser, not to the server.so Browser did not anything after the '#' character.
To resolve this issue you can try this below url rewrite rule:
<rule name="test # in query string" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="invoice/(.+)" />
</conditions>
<action type="Redirect" url="invoice.html?id={UrlEncode:{C:1}}" />
</rule>
(.+) accessts all the chracter and {UrlEncode:{}} encode the url in the orignal manner.
Regards,
Jalpa
Related
I'm fairly new to url rewrite and trying to figure this thing out.
I have a website with the following structure:
http://localhost/virtualdirectory1/somepage.aspx?parameter1=x
http://localhost/virtualdirectory2/
Now I added a rule for a redirect (inbound rule):
matches pattern (regex) ^$ to make sure that if anybody goes to http://localhost that they are redirected to http://localhost/virtualdirectory1/somepage.aspx?parameter1=x
This also works fine for http://localhost/?paramter1=x which gets redirected properly.
This still allows me to approach http://localhost/virtualdirectory2/ directly.
However if the user goes to http://localhost/somepage.aspx?paramter1=x they are not redirected to the virtualdirectory1
Could give me some tips on how that can be done?
Thanks!
Is this rule achieve your requirement? It will redirect both http://localhost and http://localhost/somepage.aspx?paramter1=x but it won't redirect http://localhost/.
<rule name="redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^(/somepage\.aspx)?$" />
</conditions>
<action type="Redirect" url="virtualdirectory1/somepage.aspx?parameter1=x" appendQueryString="false" redirectType="Temporary" />
</rule>
we have a site at something.example.com and we want it to go always redirect to www.example.com
We already have the rule in for 'adding' www. when a user just puts example.com.
But we have a test url that is in place for other reasons and we want the live site to ALWAYS redirect to www.example.com no matter what prefix it has before the domain.
just use this regex .* in <match url="" /> or IIS URL re-write pattern field
for additional information:
dot means any single char
Asterix means zero or more of a char
so .* means zero or more of any char
According to your description, I suggest you could try to use {http_host} to match the domain part in the url rewrite rule.
Details, you could refer to below rules:
<rule name="rediect" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(.*).example.com" />
<add input="{HTTP_HOST}" pattern="^example.com" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" />
</rule>
I have to domains - a.com and b.com. I want to use iis rewrite so that anything going to www.a.com/ will be redirected to www.b.com/index.asp?i=.
For example www.a.com/XXX will be redirected to www.b.com/index.asp?i=XXX
I put (.*?) in the pattern. The problem is when I enter http://www.b.com/index.asp?i={REQUEST_URI} as a redirect action, the redirect url includes a slash. For example www.a.com/XXX is redirected to www.b.com/index,asp?i=/XXX instead of to i=XXX. Is there any way to get rid of the slash?
You could use below url rewrite rule:
<rule name="test1" enabled="true" stopProcessing="true">
<match url=".+" />
<conditions>
</conditions>
<action type="Redirect" url="http://www.b.com/index.asp?i={R:0}" />
Regards,
Jalpa
I've just started using iis rewrite rules for the first time and I'm struggling with what I imagine is an easy rule.
Basically, I wish to use this rule
<rule name="redirect">
<match url="^(one$|two$|three$)" />
<action type="Redirect" url="{HTTP_HOST}{REQUEST_URI}" />
</rule>
But have the redirect {HTTP_HOST} string minus the extension [.co.uk / .com etc.].
e.g.
bigsite.co.uk/one
would redirect to:
bigsite.co.uk/bigsite/one
How does one go about this - for I can only find Tolower / UrlEncode / UrlDecode string manipulators?
[Ultimately, I would also like to then use a rewrite rule to hide the fact that the redirect has occurred, i.e. the address would remain as bigsite.co.uk/one after the redirect.]
Well I eventually came up with this (hope it may help someone):
<rule name="redirect">
<match url="^(one$|two$|three$)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?(.*).co.uk" />
</conditions>
<action type="Redirect" url="{C:2}{REQUEST_URI}" />
</rule>
...not sure if there is a better way, but it works perfectly for me - thanks all, PP
The following rule works (successfully redirects) for urls like:
www.site.com/some/path
But doesn't work (404) for urls containing + sign:
www.site.com/some/p+a+t+h
And doesn't work (404) even when encoded:
www.site.com/some/p%2Ba%2Bt%2Bh
But works, when + is going after ? sign:
www.site.com/some/path?+
Rule:
<rule name="redirectForWww" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.site.com$" />
</conditions>
<action type="Redirect" url="http://site.com/{R:0}" />
</rule>
IIS 7.0, URL Rewrite Module 2.0
The plus sign is a reserved delimiter according to URI spec # http://labs.apache.org/webarch/uri/rfc/rfc3986.html#reserved
so it cannot (or shouldn't) be used in a file/folder name in a URL. It does however have a use after a ?, in javascript GET data & mailto: links + equates to a space.