Skip to content

Instantly share code, notes, and snippets.

@sethryder
Last active April 29, 2022 18:16
Show Gist options
  • Select an option

  • Save sethryder/22c4ed1b8a7b3b31090ace2cfd39fb09 to your computer and use it in GitHub Desktop.

Select an option

Save sethryder/22c4ed1b8a7b3b31090ace2cfd39fb09 to your computer and use it in GitHub Desktop.

Revisions

  1. Seth Ryder revised this gist Oct 31, 2018. No changes.
  2. Seth Ryder revised this gist Oct 31, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion yoast_redirect_fixer.php
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,4 @@
    }

    file_put_contents('fixed_export_plain.txt', serialize($new_export_plain));
    file_put_contents('fixed_export_base.txt', serialize($new_base));
    file_put_contents('fixed_base.txt', serialize($new_base));
  3. Seth Ryder created this gist Oct 31, 2018.
    33 changes: 33 additions & 0 deletions yoast_redirect_fixer.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    <?php

    $option_value_export_plain = file_get_contents('export_plain.txt');
    $option_value_base = file_get_contents('base.txt');

    $export_plain = unserialize($option_value_export_plain);
    $base = unserialize($option_value_base);

    $new_export_plain = [];

    foreach ($export_plain as $k => $redirect) {
    $new_url = preg_replace("/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\//", "", $redirect['url']);
    $new_key = preg_replace("/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\//", "", $k);

    $new_export_plain[$new_key] = [];
    $new_export_plain[$new_key]['url'] = $new_url;
    $new_export_plain[$new_key]['type'] = $redirect['type'];
    }

    foreach ($base as $k => $redirect) {
    $new_origin = preg_replace("/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\//", "", $redirect['origin']);
    $new_url = preg_replace("/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\//", "", $redirect['url']);

    $new_base[] = array(
    'origin' => $new_origin,
    'url' => $new_url,
    'type' => $redirect['type'],
    'format' => $redirect['format']
    );
    }

    file_put_contents('fixed_export_plain.txt', serialize($new_export_plain));
    file_put_contents('fixed_export_base.txt', serialize($new_base));