Skip to content

Instantly share code, notes, and snippets.

@1davidmichael
Last active January 8, 2020 15:28
Show Gist options
  • Save 1davidmichael/1c35939c6dfb59d59c65e7a1c4ebcbe3 to your computer and use it in GitHub Desktop.
Save 1davidmichael/1c35939c6dfb59d59c65e7a1c4ebcbe3 to your computer and use it in GitHub Desktop.
Convert CSV into Apache Rewrite Map txt file
#!/usr/bin/env python3
# Usage
'''
python convert_csv_to_rewrite_map.py file.csv > rewrite_map.txt
'''
import csv
import sys
from urllib.parse import urlparse
csv_redirects = sys.argv[1]
with open(csv_redirects) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
parsed = urlparse(row[0])
print(f"{ parsed.path } {row[1]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment