Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 50 lines (36 sloc) 1.556 kb
ee8fecf @mshafrir Initial version of .htaccess generator for 301 redirecting MovableType l...
authored
1 #!/usr/bin/env python
2
3 MAX_TITLE_LEN = 44
4
5 def main():
6 month_base_urls = []
7 year_base_urls = []
8
9 in_file = open("blog_urls.txt","r")
10 out_file = open(".htaccess", "w")
11
12 for new_url in in_file:
13 new_url = new_url.strip()
14 if not new_url or not len(new_url):
15 out_file.write("\n")
16
17 elif not new_url.startswith("#"):
18 old_url = new_url.replace("http://www.function1.com", "/site", 1)[:-1]
19 old_url = old_url.replace("6-5", "65").replace("6-1", "61").replace("6-0", "60").replace("4-5", "45")
20 old_url = "%s.html" % (old_url[:min(MAX_TITLE_LEN, len(old_url))].rstrip("-"))
21 out_file.write("redirect 301 %s %s\n" % (old_url, new_url))
22
23 month_base_url = new_url[:33]
24 if month_base_url not in month_base_urls:
25 month_base_urls.append(month_base_url)
26
27 out_file.write("\n")
28 month_base_urls.sort()
29
30 for month_base_new_url in month_base_urls:
31 month_base_old_url = month_base_new_url.replace("http://www.function1.com", "/site", 1)
32 out_file.write("RedirectMatch 301 ^%s$ %s\n" % (month_base_old_url, month_base_new_url))
33
34 year_base_url = "%s/" % ('/'.join(month_base_new_url.split('/')[0:-2]))
35 if year_base_url not in year_base_urls:
36 year_base_urls.append(year_base_url)
37
38 out_file.write("\n")
39 year_base_urls.sort()
40
41 for year_base_new_url in year_base_urls:
42 year_base_old_url = year_base_new_url.replace("http://www.function1.com", "/site", 1)
43 out_file.write("RedirectMatch 301 ^%s$ %s\n" % (year_base_old_url, year_base_new_url))
44
45 in_file.close()
46 out_file.close()
47
48 if __name__ == "__main__":
49 main()
Something went wrong with that request. Please try again.