Sites such as StackExchange use URLs that contain a page code and some additional keywords, possibly for SEO. If you change anything in the additional keywords, you are still redirected to the correct long URL.

Example: the following links redirect to the same page:

As long as the page code (/questions/724) is in the link, it is valid. So, we can construct many links that still resolve to the same page, e.g.

This is very interesting for future-proof URLs, as the title of a page could change, but the URLs would still redirect to the correct page.

Can this be accomplished by using existing Drupal modules?

  • This is very interesting for future-proof URLs. That's what redirects are for...not a great idea to leave potentially loads of URLs out there all resolving to the same page. Yes you can save yourself SEO penalty with a canonical tag, but I wouldn't call it desirable necessarily. That said, you could almost certainly set something like this up using hook_url_inbound_alter() and/or hook_url_outbound_alter() (both part of core) – Clive Jun 10 '14 at 9:56
  • I'm not looking for redirects. You say the URL scheme I described is "not a great idea" but many large sites use it, lifehacker.com is another one. Surely it must make sense if they can pull it off without penalties. As for the hook_url_inbound_alter(), I imagine this is possible, but I'm looking for a solution based on existing modules only at this point. – Steven Jun 10 '14 at 10:07
  • Ah right - I wouldn't have thought there's an existing module for something quite to specific, but you never know with Drupal. Just want to check that you understand that redirecting is exactly what Amazon are doing here (as per best practice)? If you visit the first URL above, it 301 redirects to the 2nd URL. That's what I mean by redirecting - there's no decent solution to this that won't involve a redirect. All you're essentially looking for is a second set of URL aliases to be valid for your nodes, and for those aliases to forward onto the short URL version – Clive Jun 10 '14 at 10:15
  • On second thought, redirects may be okay. I noticed stackexchange does it better: you can change the keywords in the url and it redirects to the correct url. Do you know how to implement this? I will edit the question. – Steven Jun 10 '14 at 10:22
  • By the way, you got a redirect on the first link since StackExchange actually changes Amazon links it recognizes. If the link is literal, you don't get a redirect. You can check it on the revisions page drupal.stackexchange.com/posts/117764/revisions – Steven Jun 10 '14 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.