Last active
September 24, 2015 01:34
-
-
Save dirkkelly/1f421df60bae72612cc1 to your computer and use it in GitHub Desktop.
Rack::Rewrite CSV Redirect Map Parsing For Drupal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source | destination | |
---|---|---|
/lol/ | /destination/ | |
/hahaha/ | /hahaha/lol-rofl.omg.png | |
/infinite-redirect/ | /infinite-redirect/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Had to get some urls out of Drupal and into a Rack app, here's how I did it.