How to add re-write global rule with action type "Redirect to Server Farm" in powershell

Abid Zafar 21 Reputation points
2022-02-17T04:31:25.543+00:00

Hi,

In need to ask, How to add re-write global rule with action type "Redirect to Server Farm" in powershell?175187-iis-redirect-rule.jpg

I am using below command:

.\appcmd.exe set config -section:system.webServer/rewrite/globalRules /+"[name='myServerFarmRule',patternSyntax='Wildcard',stopProcessing='True'].action.type:"Reoute to Server Farm"" /+"[name='myServerFarmRule',patternSyntax='Wildcard',stopProcessing='True'].action.url:"myServerFarm/{R:0}"" /+"[name='myServerFarmRule',patternSyntax='Wildcard',stopProcessing='True'].action.logRewrittenUrl:"True"" /commit:apphost

but always giving me error as below:
Failed to process input: The parameter 'Server' must begin with a / or - (HRESULT=80070057).

Can anyone please let me know if I am doing correct or need any modification in the command, I need to "Redirect to Server Farm" in the action properties of the farm as depicted in the attached screenshot.

Regards
Abid Zafar

Internet Information Services
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,463 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce Zhang-MSFT 3,741 Reputation points
    2022-02-18T02:37:13.163+00:00

    Hi @Abid Zafar ,

    You can try this rule:

    appcmd.exe set config  -section:system.webServer/rewrite/globalRules /+"[name='arr_to_serverfarm',patternSyntax='Wildcard',stopProcessing='True']" /commit:apphost  
    appcmd.exe set config  -section:system.webServer/rewrite/globalRules /[name='arr_to_serverfarm',patternSyntax='Wildcard',stopProcessing='True'].match.url:"*"  /commit:apphost  
    appcmd.exe set config  -section:system.webServer/rewrite/globalRules /[name='arr_to_serverfarm',patternSyntax='Wildcard',stopProcessing='True'].action.type:"Rewrite" /[name='arr_to_serverfarm',patternSyntax='Wildcard',stopProcessing='True'].action.url:"http://myServerFarm/{R:0}"  /commit:apphost  
    

    Or combine them to a command line:

    appcmd.exe set config  -section:system.webServer/rewrite/globalRules /+"[name='arr_to_serverfarm',patternSyntax='Wildcard',stopProcessing='True']" /[name='arr_to_serverfarm',patternSyntax='Wildcard',stopProcessing='True'].match.url:"*" /[name='arr_to_serverfarm',patternSyntax='Wildcard',stopProcessing='True'].action.type:"Rewrite" /[name='arr_to_serverfarm',patternSyntax='Wildcard',stopProcessing='True'].action.url:"http://myServerFarm/{R:0}"  /commit:apphost  
    

    I have tested them and they can work well.
    175579-1.png


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Bruce Zhang


1 additional answer

Sort by: Most helpful
  1. MotoX80 32,911 Reputation points
    2022-02-17T15:56:21.98+00:00

    Route is misspelled and you have double quotes around some values where you should use single quotes. Try this.

    .\appcmd.exe set config -section:system.webServer/rewrite/globalRules /+"[name='myServerFarmRule',patternSyntax='Wildcard',stopProcessing='True'].action.type:'Route to Server Farm'" /+"[name='myServerFarmRule',patternSyntax='Wildcard',stopProcessing='True'].action.url:'myServerFarm/{R:0}'" /+"[name='myServerFarmRule',patternSyntax='Wildcard',stopProcessing='True'].action.logRewrittenUrl:'True'" /commit:apphost
    

    Note, I did not test this.

    0 comments No comments