Skip navigation.

SQL Query for mapping Drupal Node Titles to URL Aliases

I'm not sure how often you need to do this, but if you've ever wanted to build a cheat sheet that matches Drupal page titles to each page's clean url then here's the SQL query that'll do the trick:

select n.title as Title, u.dst as URL, u.pid as ID from (select title, concat('node/', nid) as realurl from node) as n join url_alias u on n.realurl = u.src order by n.title, u.pid desc

To avoid broken links Drupal tends to hang on to old aliases.  So for better or worse you can end up with duplicate URLs for the same page and title.  For that reason I've included the index id for the aliaes in the query and then used them as a secondary sort.  At least in Drupal 6 and below the highest Alias ID corresponds to the most recently created alias.  Which is most likely to be the "correct" one.  Oh yeah, and I've included the index id for pages as well because in Drupal it's possible for two pages to have the same title.

The result's going to look something like this

 

Page IDTitleURLAlias ID
2312009 - 2010 Wholesale Price List2009-2010-wholesale-price-list897
2312009 - 2010 Wholesale Price List2009-2010_pricelist_wholesale837
2312009 - 2010 Wholesale Price Listnursery/wholesale_price_list836
2312009 - 2010 Wholesale Price Listpricelist835
242Availability Updateblog/2010-11/availability-update874
246Availbility Sheetnodeavailbility-sheetnode900
202Before and After Photosand-after-photos878
202Before and After Photosbefore_after755
202Before and After Photosbefore_after754
202Before and After Photosbeforeandafters753
206Catalogcatalog767
206Catalogcatalog766

In case you're curious I use lists like this as a link-mapping tool when I import an old website's pages into Drupal.  Once the pages are imported, the titles straigthened out, and the URLs mapped into a decent hierarchy I can use this list when I go through the actual content (remember content?) and replace old urls with new correct ones.

There's probably a more intelligent...or at least less complicated way to do it, but this works for me.  For a small site you wouldn't bother, but if you're importing hundreds or thousands of pages it's... kind of helpful.

yKgRUhGUfCnuF

accycogva,

FQqNWmhfgrkaMWVY

lEUZnnoMeTsOZ

tairaiguewitch,

yHdeVMWmAzGzP

softmoncdero,

qfZjOlGZEXuqUQxfeMR

LXdfbZSDRgNbEykM

resbackvama,

dCxlCyJDCYTWj

dowscugy,

HDXAYclFlCZNx

cangttimicer,

nNLqTBQHVsoVRMyzJZK

fervoucus,

LXyTHFEDCPBWzm

xagtuffdogg,

vDGWErHJpa

marlidis,

vqaLYVbdVPqShNSTMb

hopmerates,

thrPunfoNQBomErkP

comment4, http://genericcialisdrugstorerx.com/ Cialis, cfb, http://cialisonlinepharmrx.com/ Order Cialis Online, ewqiu,

OGthnCXmDXflZNsi

nPshWjQSNKlFdGCN

urexglitro,

hFGRvFhTwckiAE

iuakpddn, lasix, ruhmbpog, buy viagra australia, hvvgaioo, buy generic cialis, euahusxj, uk cialis sales, kpfbiiqk,

cyBwyrBWNPlMG

comment2, http://genericcialisdrugstorerx.com/ Buy Cialis Generic, >:-(, http://tadalafilrxpharm.com/ Generic Cialis, 3944, http://cialisonlinepharmrx.com/ cheap Cialis online, 8-OOO,

hlJSvETvqbDqnREJ

vdEAYufEpaxvXMmDaSI

PhTQIfoRYPGYEbQKOLc

cqvpwbzn, viagra barata, qcaaoxil, farmacias cialis, hhziarlt, accutane sale, ijzrhwlz, lasix, abzuczrd,

BGllgUQrQoNqDvos

sneezponriadwud,

HzLHOAtxNXEEXPGeqJe

jQszzLPcZrt

cuisutippearb,

DBhYEZJWOaePX

NzkfPaDeJYNPyl

rVmfGMaEMBN

xAULoutWHZfbXPOucV

vorsscafem,

UcbnjeyqeRrnePivd

sesobsu,

SeTbNyjFGXpWHq

thiablocerseen,

KuRQpgEDqWYpEA

iLSaBrMmQSxrtMw

onbgQYXqla

vairougvecos,

bpeFGVLIZIFkElv

jHdACInWTqFJVqtuKHc

nobwestcom,