I want to create a rewrite rule in IIS 8.5 so that the TLD in the url gets changed from .com to .net.
example:
from: http://sub.domain.com/index.aspx?test=123
to: http://sub.domain.net/index.aspx?test=123
At the moment I got something like this in my web.config but is doesn't seem to work:
<rule name="TLD" enabled="false">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?([a-z]*.)(domain)(.com)(/?.*)$" />
</conditions>
<action type="Rewrite" url="http://{C:2}{C:3}.net/{C:5}" />
</rule>
Any suggestions?
I was looking for the exact same problem and found this
<rule name="WWW" enabled="true" stopProcessing="true">
<match url=" (.*)"/>
<conditions >
<add input="{HTTP_HOST}" pattern="^(www\.)?example\.old$"/>
</conditions>
<action type="Redirect" url="h++p://example.com/{R:1}" redirectType="Permanent" />
</rule>
Found it here: ReWrite top-level domain (TLD)
Related
I have an aspx web app accessed via http://domain/web.aspx. This web app uses port 80 and http://domain:80/web.aspx works OK. I would like to redirect all calls to https://domain:82/web.aspx. I've tried using the rewrite rule
<rule name="HTTPS force" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*):80$" />
</conditions>
<action type="Redirect" url="https://localhost:82" appendQueryString="false" />
</rule>
in web.config in the same folder as web.aspx but this has no effect. What rewrite rule do I need to use?
You should use the following as input:
<rule name="HTTPS force" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Permanent" />
</rule>
Not sure if you want the :80 there in the URL? If so, it can be added to my example too. Taken from here: Web.config redirects with rewrite rules - https, www, and more.
Found this rule worked
<rule name="HTTPS force" enabled = "true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="http://domain/Web.aspx" />
</conditions>
<action type="Redirect" url="https://domain:82/Web.aspx"/>
</rule>
I'm trying to simply do a subdomain rewrite to a directory. Example, http*://member.mydomain.com would redirect to http*://mydomain.com/memberarea/. I don't want ALL subdomains to do this, just the defined "member" one.
Here is the code I have, and it does not work. I'm obviously missing something...
<rule name="Member Pages" stopProcessing="true">
<match url="^(.+)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*)://member\.example\.com($)" />
</conditions>
<action type="Redirect" url="{C:1}://example.com/MemberArea/{R:1}" />
</rule>
My hope is this would also make http://member.example.com/Report/SomeReport.aspx resolve to http://example.com/MemberArea/Report/SomeReport.aspx.
Any help would be greatly appreciated.
You can try this rule will be redirected to the http*://member.mydomain.com http*://mydomain.com/memberarea/
<rule name="test2" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^member\.(.*)$" />
</conditions>
<action type="Redirect" url="http://{C:1}/memberarea" />
</rule>
I have setup a url rewrite rule to redirect from one domain to another in case matching the condition. i have a site abc.aaa.com which should redirect to abc.bbb.com if url matches with *.aaa.com. When I hard code the action URL its working fine but using back reference its not working.
I am using IIS 8.5
Below are the rules.
This is not working. When I am doing this URL is showing http://abc.aaa.com/abc.bbb.com
<rule name="Redirect aaa.com" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*).aaa.com(.*)$" />
</conditions>
<action type="Redirect" url="{C:1}.bbb.com{C:2}" appendQueryString="false" />
</rule>
This is working
<rule name="Redirect aaa.com" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*).aaa.com(.*)$" />
</conditions>
<action type="Redirect" url="http://abc.bbb.com" appendQueryString="false" />
</rule>
I have tried the same pattern in rule pattern and same action without condition. thats also not working
<rule name="Redirect aaa.com" enabled="true" stopProcessing="true">
<match url="(.*).aaa.com(.*)$" />
<action type="Redirect" url="http://abc.bbb.com" appendQueryString="false" />
</rule>
I have found that {C:1} doesn't contain http:// part and seperated that in URL action . it's working fine.Below is the modified rule
Thanks Lex Li for the quick response
<rule name="Redirect aaa.com" enabled="true" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*).aaa.com(.*)$" />
</conditions>
<action type="Redirect" url="http://{C:1}.bbb.com{PATH_INFO}" appendQueryString="true" />
</rule>
I have multiple domain names pointed to the same server (example.nl)
The example.my url should point to the content of example.nl/en, without having this url to appear in the adress bar. This is only really necessary for the homepage (due to google addwords issues).
To summarize, example.my should show the content of example.nl/en while showing example.my in the adress bar.
The current rule is giving me an error. Any tips?
<rule name="Redirect .my" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^.*example\.my$" />
</conditions>
<action type="Rewrite" url="http://www.example.nl/en/" />
</rule>
This seems to do the trick for me:
<rule name="redirect .my to /en" enabled="true" stopProcessing="true">
<match url="(^$)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="example.my" />
</conditions>
<action type="Redirect" url="http://www.example.my/en/{R:1}" appendQueryString="true" />
</rule>
I would like to match exactly https://internet.dev.local/KYR url (without / into end) and redirect or rewrite to https://internet.dev.local/KYR/ (with /).
I am trying the following rule but it matches other URLs as well e.g. https://internet.dev.local/KYR/Admin/Form/Default.aspx?signup=false, which is wrong.
so how can I achieve this?
<rule name="Static redirect" patternSyntax="ExactMatch" stopProcessing="true">
<match url="https://internet.dev.local/KYR" negate="true" />
<conditions>
</conditions>
<action type="Redirect" url="/Login/?ReturnUrl=/Member/KYR/" redirectType="Permanent" />
</rule>
If you need to test the host and protocol you have to put it in the conditions, not in the global rule.
Following your example, it would be as follow:
<rule name="test" patternSyntax="ExactMatch" stopProcessing="true">
<match url="KYR" />
<action type="Redirect" url="/KYR/" redirectType="Permanent" />
<conditions>
<add input="{HTTP_HOST}" pattern="internet.dev.local" />
<add input="{HTTPS}" pattern="on" />
</conditions>
</rule>
I have changed the url in the action because your question says:
redirect or rewrite to https://internet.dev.local/KYR/ (with /).
EDIT:
To get it to work on any host (with or without SSL), just remove the conditions:
<rule name="test" patternSyntax="ExactMatch" stopProcessing="true">
<match url="KYR" />
<action type="Redirect" url="/KYR/" redirectType="Permanent" />
</rule>