26

Is it possible to export URL rewrite rules for IIS7?

I am setting up a duplicate of a website for internal use (testing) and want to duplicate all of the URL Rewrite rules without having to manually enter them.

There is an import option, but no obvious 'export'...

Thanks!

Matt
  • 409
  • 1
  • 5
  • 11

1 Answers1

35

I think you have 2 options:

You could look in the web.config file, and copy the <rewrite> section, then paste into the web.config file on the new system.

Or, you could use appcmd to export the rules to a file, and to import them on the new system:

Export:

appcmd list config "websitename/appname" -section:system.webServer/rewrite/rules -xml > rewriterules.xml

Import (globaly on the server):

appcmd set config -in < rewriterules.xml

Import for a specific website:

 appcmd set config "testWebsite\" -in < rewriterules.xml

You can also export any global rewrite rules using:

appcmd list config -section:system.webServer/rewrite/globalRules -xml > globalrewriterules.xml

The import command would be the same.

Koenman
  • 3
  • 3
MattB
  • 11,194
  • 1
  • 30
  • 36
  • Cheers! I'm so used to working with Apache that I forgot about the web.config! Thanks again! – Matt Feb 16 '10 at 21:02
  • for info on using appcmd check out here: http://learn.iis.net/page.aspx/114/getting-started-with-appcmdexe/#HowToUse – brendan Nov 02 '10 at 14:54
  • Your import command i.e. `appcmd set config -in < rewriterules.xml` imported globally and it really messed up the server until I realized my mistake. – Sohail Ahmed Aug 17 '16 at 17:23
  • The command `appcmd list config "websitename/appname" -section:system.webServer/rewrite/rules -xml > rewriterules.xml` doesn't really export ehe rules to XML in IIS 10.5. There is no error, but the output XML is blank. Hoever when I execute `appcmd list config "websitename/appname" -section:system.webServer/rewrite/rules` I am getting all the rewrite rules on cmd. – keenUser Aug 03 '20 at 08:38