Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Redirect imports #47

Open
AndrewHaine opened this issue Jun 5, 2020 · 3 comments
Open

[FR] Redirect imports #47

AndrewHaine opened this issue Jun 5, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@AndrewHaine
Copy link
Contributor

Have a CSV import for the redirects table in the CMS

@AndrewHaine AndrewHaine added the enhancement New feature or request label Jun 5, 2020
@HRR1337
Copy link

HRR1337 commented Feb 22, 2021

This would be soooo nice... Or atleast an way to redirect fast :p

@marnickmenting
Copy link

I have a .htaccess file with lots of RedirectMatch 301 lines, would be nice to import these is in some way. Or provide a command to import it.

@marnickmenting
Copy link

marnickmenting commented Oct 8, 2024

For reference, I created a simple use-once PHP script to convert .htaccess to Aardvark Redirects, maybe it helps someone. Run it with 'php <filename.php>' and copy-paste the output into storage/statamic/addons/aardvark-seo/aardvark_redirects/manual.yaml

<?php

$redirects = "<Put your RedirectMatch 301 lines here>";

$split = explode("\n", $redirects);

function uuidv4()
{
    $data = random_bytes(16);

    $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
    $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10

    return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}

foreach($split as $line) {
    $line = str_replace('    RedirectMatch 301 ', '', $line);
    $splits =  explode(' ', $line);
    echo "  -
    source_url: $splits[0]
    target_url: $splits[1]
    status_code: '301'
    is_active: true
    id: " . uuidv4() . "
";
}

/* Outputs:
  - source_url: ^/source$
    target_url: /target
    status_code: '301'
    is_active: true
    id: e60f205d-2cf6-4702-89c1-2282b4820ccc
*/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants