I have the following rewrite rule to redirect any conetnt from a host, hostA.com to the home page of a new host, hostB.com. I also want to browser url to change to www.HostB.com
<rewrite>
<rules>
<rule name="301 redirect entire site" stopProcessing="true">
<match url="^hostA(.*)$" />
<action type="Redirect" redirectType="Permanent" url="http://www.hostB.com" appendQueryString="true" />
</rule>
</rules>
</rewrite>
But that does not work. How can I fix this please.
you can doit like this
<rule name="domain redirect" enabled="true" stopProcessing="true">
<match url="^hostA(.*)$" />
<action type="Redirect" url="http://hostb.example.com/{R:0}" appendQueryString="true" />
</rule>
Related
I have iis rewrite rule as follows.
<rule name="Redirect url1" stopProcessing="true">
<match url="^nsg/([!-~]+)" />
<action type="Redirect" url="https://test.com/gsl/{R:1}"
appendQueryString="true" redirectType="Permanent" />
</rule>
Which is successful when I type in https://test.com/nsg/tasksearch.aspx, it will redirect to https://test.com/gsl/tasksearch.aspx. However, I also want it
when I just type in https://test.com/nsg, it can redirect to https://test.com/gsl. Can I do that?
Just a simple change from your regular expression. Please try the below rules.
<rewrite>
<rules>
<rule name="MyRule" stopProcessing="true">
<match url="^nsg([!-~]*)" />
<action type="Redirect" url="https://test.com/gsl{R:1}" />
</rule>
</rules>
</rewrite>
Feel free to let me know if the problem still exists.
After researching url rewrite and reviewing many posts, I'm still stumped as to why my url rewrite is not working. I am attempting to remove /carrot/ from the path.
Ex: https://my.server.com/carrot/mobile/path
should become: https://my.server.com/mobile/path
My URL rewrite rule is pretty simple and looks as follows:
<rule name="RemoveCarrotFromPath">
<match url=".*carrot(.*)" />
<action type="Rewrite" url="{R:1}" />
</rule>
All help is appreciated.
Edit Below you can find all rules in use in case this is an issue where various rules are clashing:
<rewrite>
<rules>
<rule name="redirectPayment" stopProcessing="true">
<match url="/payment" />
<action type="Redirect" url="https://my.app.com/carrot/Payment" />
</rule>
<rule name="redirectMembership" stopProcessing="true">
<match url="/membership" />
<action type="Redirect" url="https://my.app.com/carrot/Membership" />
</rule>
<rule name="RemoveCarrotFromPath">
<match url=".*carrot(.*)" />
<action type="Rewrite" url="{R:1}" />
</rule>
</rules>
</rewrite>
The solution to my issue was to use Redirect instead of Rewrite as follows:
<rule name="RemoveCarrotFromPath">
<match url=".*carrot(.*)" />
<action type="Redirect" url="{R:1}" />
</rule>
Please, I have this folder:
root/teste_seo/script.asp
Instead to use the url:
www.mysite.com/teste_seo/script.asp
I need this url using IIS rewrite:
www.mysite.com/script.asp
I try to use the rule from this link but didn't work:
IIS 7.5 URL Rewrite - Rewrite a Folder from an URL
Please, how can I write this rule?
PS.: For any *.asp file inside teste_seo folder.
The following rule should do the trick:
<rule name="teste_seo" stopProcessing="true">
<match url="^script.asp" />
<action type="Rewrite" url="/teste_seo/script.asp" />
</rule>
Then just link to the www.mysite.com/script.asp
Edited after comment from OP:
If so you can use the following rule as long as you have a copy of the script files in the root of your document:
<rule name="teste_seo" stopProcessing="true">
<match url="^teste_seo/([^\.]+\.asp)" />
<action type="Redirect" url="/{R:1}" />
</rule>
And if you need all script files to point to the same one you can use:
<rule name="teste_seo" stopProcessing="true">
<match url="^teste_seo/([^\.]+\.asp)" />
<action type="Redirect" url="/script.asp" />
</rule>
Edited again after clarification:
These 2 rules should then be the fix you need:
<rule name="teste_seo_redirect" stopProcessing="true">
<match url="^teste_seo/([^\.]+\.asp)" />
<action type="Redirect" url="/{R:1}" />
</rule>
<rule name="teste_seo_rewrite" stopProcessing="true">
<match url="^([^\.]+\.asp)" />
<action type="Rewrite" url="/teste_seo/{R:1}" />
</rule>
I wish to redirect ALL pages from a specific folder and its subfolders to a page on root folder. I have written the following rule in IIS 7.5 but it is not working. Please advise.
<rule name="someName" stopProcessing="true">
<match url="/MoveFromThisFolder/.*" />
<action type="Rewrite" url="/ToThisFile.html" appendQueryString="false" />
</rule>
I modified the rule as follows and it worked for me!
<rule name="SomeRule" stopProcessing="true">
<match url="^FromThisFolder/(.*)" />
<action type="Redirect" url="ToThisFile.html" appendQueryString="false" />
</rule>
Try getting rid of the leading "/"
<rule name="someName" stopProcessing="true">
<match url="^MoveFromThisFolder/($|[\?/].*)" />
<action type="Rewrite" url="ToThisFile.html" appendQueryString="false" />
</rule>
I'm running IIS 7 with the offical rewrite rule module installed. I'd like to create a rewrite rule to match this URL:
http://www.sample.com/en-us/test.aspx?q=keyword
After rewriting the expected result would be:
http://www.sample.com/en-us/test.aspx?q=keyword&flag=value
How can I create a rule to implement this?
I've tested the following rule, but no luck, it always got redirect loop error:
<rewrite>
<rules>
<rule name="test" stopProcessing="true">
<match url="(.*)/test\.aspx(.(?!flag=value))*$" />
<action type="Redirect" url="{R:0}&flag=value" appendQueryString="false" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
Found the solution by myself, just share it.
<rewrite>
<rules>
<rule name="Redirect for download result page" stopProcessing="true">
<match url="(.*)/test.aspx(.*)" />
<action type="Redirect" url="{R:1}/test.aspx?rf=sp" appendQueryString="true" redirectType="Found" />
<conditions>
<add input="{QUERY_STRING}" pattern="flag=value" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>