Skip to content

Instantly share code, notes, and snippets.

@deep-spaced
Forked from stevemeisner/301 Insert.sql
Last active December 23, 2015 10:38
Show Gist options
  • Select an option

  • Save deep-spaced/6622454 to your computer and use it in GitHub Desktop.

Select an option

Save deep-spaced/6622454 to your computer and use it in GitHub Desktop.
Updated redirect creation method for Typewriter.
INSERT INTO `redirects` (`match`, `redirect_to`, `account_id`, `created_at`, `updated_at`)
VALUES
('/old_page.php', '/new/page', 40, NOW(), NOW()),
('/old_page_two.php', '/new/page/two', 40, NOW(), NOW()),
('/old_page_three.php', '/new/page-two', 40, NOW(), NOW());

Begin

  1. Go to http://www.xml-sitemaps.com/ and generating the sitemap from the current (old) site.
  2. Choose the option to "Download Sitemap in Text Format". It will give you "urllist.txt" with each result on one line.
  3. Open this file and add the redirects in the following fashion: old_page.php, /new/page
  4. Convert to SQL by using the following find and replace:

Sublime

Find: , Replace: ', '

Find: \n Replace: ', {ACCOUNT ID}, NOW(), NOW()),\n\t('

BBEdit

Find: , Replace: ', '

Find: \r Replace: ', {ACCOUNT ID}, NOW(), NOW()),\r\t('

{ACCOUNT ID} should be replaced by the numerical ID of the account.

Add

To the beginning of your text file:

INSERT INTO `redirects` (`match`, `redirect_to`, `account_id`, `created_at`, `updated_at`)
VALUES

Run

  1. Save the file as redirects.sql.
  2. Run it on your local Typewriter database.
  3. Test locally before running live.
  4. Relax!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment