Set rewrite url for virtual directory using appcmd.exe

Jagadeesh Mohan 1 Reputation point
2022-06-25T16:10:18.43+00:00

I can set re-write url using below cmd for iis site. But i want to do the same for virtual directory.

appcmd.exe set config "Default Web Site" -section:system.webServer/rewrite/rules /+""[name='ReverseProxyRule',enabled='True']"" /commit:apphost"

How to enable re-write url for virtual directory using appcmd.exe

Similar to below cmd i am expected:
appcmd.exe set config "Default Web Site\mobile_vir_dir" -section:system.webServer/rewrite/rules /+""[name='ReverseProxyRule',enabled='True']"" /commit:apphost"
(have to use the virtual directory name "mobile_vir_dir")

Windows development Internet Information Services
Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yurong Dai-MSFT 2,846 Reputation points Microsoft External Staff
    2022-06-28T02:57:44.637+00:00

    Hi @Jagadeesh Mohan ,

    You can try the following command line:(The following example is to create a rewrite rule to "redirect to HTTPS" by using appcmd)

    appcmd.exe set config "Default Web Site/mobile_vir_dir" -section:system.webServer/rewrite/rules /+"[name='Redirect to HTTPS']"   
    appcmd.exe set config "Default Web Site/mobile_vir_dir" -section:system.webServer/rewrite/rules /"[name='Redirect to HTTPS'].match.url:"(.*)""    
    appcmd.exe set config "Default Web Site/mobile_vir_dir" -section:system.webServer/rewrite/rules /+"[name='Redirect to HTTPS'].conditions.[input='{REQUEST_FILENAME}',matchType='IsFile']"   
    appcmd.exe set config "Default Web Site/mobile_vir_dir" -section:system.webServer/rewrite/rules /+"[name='Redirect to HTTPS'].conditions.[input='{REQUEST_FILENAME}',matchType='IsDirectory']"   
    appcmd.exe set config "Default Web Site/mobile_vir_dir" -section:system.webServer/rewrite/rules /"[name='Redirect to HTTPS'].action.type:"Rewrite"" /"[name='Redirect to HTTPS'].action.url:"client/index.htm""   
    

    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,
    Yurong Dai

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.