Skip to content

Instantly share code, notes, and snippets.

@dirkkelly
Last active September 24, 2015 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirkkelly/1f421df60bae72612cc1 to your computer and use it in GitHub Desktop.
Save dirkkelly/1f421df60bae72612cc1 to your computer and use it in GitHub Desktop.
Rack::Rewrite CSV Redirect Map Parsing For Drupal
use Rack::Rewrite do
CSV.read("redirects.csv", headers: true).each do |row|
# Lol, yes we had redirects of source to destination, yay Drupal!
if row["source"] != row["destination"]
r301 row["source"], row["destination"]
end
end
end
SELECT
REPLACE(CONCAT('/', REPLACE(REPLACE(alias.alias, ' ', ''), ' ',''), '/'), '//', '/') AS source, # I don't know why there are two different space objects
REPLACE(CONCAT('/', REPLACE(destination.field_destination_url_value, ' ', ''), '/'), '//', '/') AS destination
FROM node
INNER JOIN field_data_field_destination_url destination
ON destination.entity_id = node.nid
INNER JOIN url_alias alias
ON alias.source = CONCAT('node/', node.nid)
WHERE type='marketing_url_redirect';
SELECT
REPLACE(CONCAT('/', REPLACE(REPLACE(IF(ISNULL(node.nid), redirect.source, node_alias.alias), ' ', ''), ' ',''), '/'), '//', '/') AS source,
REPLACE(CONCAT('/', REPLACE(IF(ISNULL(alias.alias), redirect.redirect, REPLACE(REPLACE(alias.alias, ' ', ''), ' ','')),'<front>',''), '/'), '//', '/') AS destination
FROM redirect
LEFT JOIN url_alias alias
ON redirect.redirect = alias.source
LEFT JOIN node
ON redirect.source = CONCAT('node/', node.nid)
LEFT JOIN url_alias node_alias
ON redirect.source = node_alias.source;
source destination
/lol/ /destination/
/hahaha/ /hahaha/lol-rofl.omg.png
/infinite-redirect/ /infinite-redirect/
@dirkkelly
Copy link
Author

Had to get some urls out of Drupal and into a Rack app, here's how I did it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment