modules

a drupal path redirect bookmarklet

i threw together a fancy little javascript bookmarklet to create redirects in drupal, and figured i'd share:

<a href="javascript:d='example.com/';location.href='http://'+d+'admin/build/path_redirect/new?edit[redirect][redirect]='+encodeURIComponent(location.href.split(/[\?#]/)[0].replace(RegExp('https?://'+d,'ig'),''))+'&edit[redirect][query]='+encodeURIComponent(location.href.indexOf('?')&gt;-1?location.href.split(/[\?#]/)[1]:'')+'&edit[redirect][fragment]='+encodeURIComponent(location.href.indexOf('#')&gt;-1?location.href.split(/#/)[1]:'')+'&edit[path]='+encodeURIComponent(String(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text)).replace(/[^a-zA-Z0-9]+/g,'-').toLowerCase());">new path redirect</a>

for this to work you need the path redirect and prepopulate modules installed... then simply replace "example.com" in the snippet above with your domain name, and save the link as a browser bookmark.

now click on it, and it will add a redirect to the current page. if you select any text before clicking the bookmarklet, it will use that text for the redirect path. this bookmarklet supports both internal (drupal) and external paths. it also works with urls containing queries (?foo=bar) and fragments (#baz). tested in ie, firefox and safari.

have fun!