How to add URL Rewrite using command line [Answered]RSS

7 replies

Last post Jan 17, 2019 02:58 PM by lextm

  • How to add URL Rewrite using command line

    Jan 15, 2019 02:56 AM|trongthai|LINK

    I searched many places but nowhere is there a way to create a rewrite url using cmd.
    Someone please help me.

  • Re: How to add URL Rewrite using command line

    Jan 15, 2019 07:07 AM|Jalpa Panchal|LINK

    Hi trongthai,

    To add match url in rewrite rule using appcmd use below command:

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

    output:

    <rule name="Redirect to HTTPS">
    <match url="(client*)" />
    <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
    </conditions>
    <action type="Rewrite" url="client/index.html" />
    </rule>

    You could also refer https://forums.iis.net/t/1240029.aspx post.

    Regards,

    Jalpa.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: How to add URL Rewrite using command line

    Jan 15, 2019 07:13 AM|trongthai|LINK

    Thanks Jalpa Panchal,

    That's exactly what I need.

    Thank you so much.

  • Re: How to add URL Rewrite using command line

    Jan 15, 2019 07:18 AM|Jalpa Panchal|LINK

    Hi,

    From your post, I can see that your issue in the original post is solved now. i request you to mark the helpful suggestion as an answer. 

    Thank you for understanding.

    Regards,

    Jalpa.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: How to add URL Rewrite using command line

    Jan 15, 2019 09:52 AM|trongthai|LINK

    In case I created a new website and didn't have a web.config file, what should I do?

  • Re: How to add URL Rewrite using command line

    Jan 16, 2019 06:03 PM|lextm|LINK

    Lex Li
    IIS Consulting Services at https://support.lextudio.com/services/consulting.html
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: How to add URL Rewrite using command line

    Jan 17, 2019 02:06 AM|trongthai|LINK

    I tried this and got an error:

    'Add-WebConfigurationProperty' is an internal command or external command,
    It is not recognized as an operable program or batch file.

  • Re: How to add URL Rewrite using command line

    Jan 17, 2019 02:58 PM|lextm|LINK

    1. Write a PowerShell script like the blog post said.
    2. Call this script at command prompt.

    I am not asking you to call "Add-WebConfigurationProperty" at command prompt, as that obviously won't work.

    Lex Li
    IIS Consulting Services at https://support.lextudio.com/services/consulting.html
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.