Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a module for Drupal that would allow me to perform redirects based on parts of the URL?

For example, if the URL contains this-string-to-redirect, e.g. example.com/this-string-to-redirect/node/content, then redirect to another path.

share|improve this question

closed as off-topic by kiamlaluno Jul 13 at 12:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking to recommend or find a book, tool, module, theme, distribution, tutorial, or other off-site resource are off-topic for Drupal Answers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – kiamlaluno
If this question can be reworded to fit the rules in the help center, please edit the question.

you might be able to do it in your .htaccess file like this: RedirectMatch 301 path-to-redirect(.*) new-path/$1 if the rest of the path is identical – Jimajamma Apr 4 '12 at 19:32
i was hoping drupal had a module so that I can teach a user to handle rewrites for the future. But it's looking like .htaccess rewrite rules may be the only way. – Mechaflash Apr 4 '12 at 21:23
Considering the comment reported in the settings page for the Path redirect module, I would say that rewrite rules are preferable, at least from the performance point of view: "If you need advanced redirection functionality (i.e. wildcards, etc.), you should be using a webserver rewriting engine rather than this module." – kiamlaluno Apr 5 '12 at 17:17
Also you should have indicated you tried the standard solutions before asking. It's impossible to guess from your formulation. – Countzero Apr 5 '12 at 17:21
@Countzero If you knew what the modules actually did prior to posting information about them, you would know that they only perform redirects on exact paths. Which is why the question and example is worded the way it is. btw I didn't downvote you. But they probably downvoted cause you off-linked instead of giving useful information in your answer. And I take it you downvoted my question because someone downvoted your answer. – Mechaflash Apr 6 '12 at 14:56
up vote 3 down vote accepted

If you want to do this yourself, quick and dirty, it would be something like this:

function yourmodule_init() {


  if ($bar[0]=='this-string-to-redirect') {




You might also want/need to throw in a weight of -1 to make sure your module runs early by putting:

function yourmodule_install() {
  db_query('UPDATE {system} SET weight = -1 WHERE name = "yourmodule"');

in yourmodule.install but a quick look just now shows globalredirect's weight at the default of 0 so this may be unneeded.

share|improve this answer
this looks promising. I'll play around with this. Thanks. Maybe now I'll be a drupal module builder =D – Mechaflash Apr 6 '12 at 14:51

If the Path Redirect module (whose Drupal 7 version is the Redirect module) doesn't help you, it might be worth taking a look at Global Redirect as well.

Path redirect

This module allows you to specify a redirect from one path to another path or an external URL, using any HTTP redirect status.

Global Redirect

GlobalRedirect is a simple module which…

  • Checks the current URL for an alias and does a 301 redirect to it if it is not being used.
  • Checks the current URL for a trailing slash, removes it if present and repeats check 1 with the new request.
  • Checks if the current URL is the same as the site_frontpage and redirects to the frontpage if there is a match.
  • Checks if the Clean URLs feature is enabled and then checks the current URL is being accessed using the clean method rather than the 'unclean' method.
  • Checks access to the URL. If the user does not have access to the path, then no redirects are done. This helps avoid exposing private aliased node's.
  • Make sure the case of the URL being accessed is the same as the one set by the author/administrator. For example, if you set the alias "articles/cake-making" to node/123, then the user can access the alias with any combination of case.
  • Most of the above options are configurable in the settings page. In Drupal 5 you can access this after enabling the globalredirect_admin module. In Drupal 6, the settings page is bundled into the module.
share|improve this answer
My question is specific to partial paths and string-in-string type filtering which all of the modules I've found don't accomplish this task (including Path Redirect and Global Redirect) – Mechaflash Apr 5 '12 at 13:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.