How to create redirects programmatically

Created on 12 June 2018, over 6 years ago
Updated 12 November 2023, about 1 year ago

Is it possible to do something like this?

redirect_insert_or_update('/from/path', 'internal:/node/123');
redirect_insert_or_update('/from/path/2', 'https://google.com');
💬 Support request
Status

Fixed

Version

1.0

Component

Documentation

Created by

🇨🇦Canada alberto56

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom noopal

    Hi, thanks, is there an option for deleting or updating programmatically?

    Redirect::create([
      'redirect_source' => 'my/path',
      'redirect_redirect' => $external,
      'status_code' => 301,
    ])->save();

    $external is no longer at the address and needs to be updated to new address? Is it possible to do something like Redirect::update 'redirect_redirect' where 'redirect_source' = 'my/path'?

    Thanks

Production build 0.71.5 2024