0

I'm trying to create a 301 redirect from a link from my old site format(because links are coming in from this URL).

The URL I'd like to redirect is like this:

http://www.example.com/Default.aspx?id=index

I'd like to simply have the above url redirect to the homepage:

http://example.com

I've tried several options, but nothing seems to be working. Any help?

1 Answer 1

1

Assuming this question is about D7, you can use the Rules module for this, with a custom rule that looks like so:

{ "rules_redirect_some_path_to_the_frontpage" : {
    "LABEL" : "Redirect some path to the frontpage",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "text_matches" : {
          "text" : [ "site:current-page:path" ],
          "match" : "Default.aspx?id=index",
          "operation" : "starts"
        }
      }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "Sorry, the old path is no longer in use, you will be redirected automatically to the homepage" } },
      { "redirect" : { "url" : "[site:url]" } }
    ]
  }
}

If you have the Rules UI module enabled, you should be able to just import the above rule, then "enable" it, and that's all you'd need to do.

What this rule actually does:

  • Check if the current path is Default.aspx?id=index
  • If that's indeed the path, then a redirect to your frontpage will be performed.

Note: feel free to adapt the first Rules Action (to display a message), or if you don't want such message at all, just remove that Rules Action.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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