Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FGFW/776a275ef977074acf9b to your computer and use it in GitHub Desktop.
Save FGFW/776a275ef977074acf9b to your computer and use it in GitHub Desktop.
python-IIS7.5-web.config-rewrite规则转.htaccess.py
"""
python-IIS7.5-web.config-rewrite规则转.htaccess.py
2016年3月8日 12:02:31 codegay
"""
import re
with open("Web.config",encoding="utf-8") as f:
txt=f.read()
with open(".htaccess","w+") as f:
ref=re.findall(r"""<rule name.+?match url="(.+?)".+?url="(.+?)".+?</rule>""",txt,16)
results=["RewriteRule "+r[0]+"$ "+r[1].replace("{R:1}","$1").replace("{R:2}","$2")+" [L]\n" for r in ref]
print(results)
f.writelines(results)
#2016年3月8日 12:39:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment