-
-
Save danielmcclure/0d92236a2b4c59dd6da988c193ed187e to your computer and use it in GitHub Desktop.
Export Yoast SEO Redirection rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Generate redirection plugin (https://wordpress.org/plugins/redirection/) compatible csv files from Yoast SEO Premium's redirection. | |
* | |
* Usage: download and put this file to root directory of your WordPress installation. | |
* then visit the url, you will see the csv file :) | |
* after then WP Adming > Tools > Redirection > import (section) | |
* | |
* | |
* Don't use this file on production | |
* | |
*/ | |
require_once 'wp-load.php'; | |
$fileName = 'yoast_to_redirection.csv'; | |
header( 'Content-Type: application/excel' ); | |
header( 'Content-Disposition: attachment; filename="' . $fileName . '"' ); | |
$fp = fopen( 'php://output', 'w' ); | |
$rules = get_option( 'wpseo-premium-redirects-base' ); | |
// header info | |
fputcsv( $fp, array( "source URL", "target URL", "regex", "http code" ) ); | |
foreach ( $rules as $redirect_item ) { | |
fputcsv( $fp, array( | |
'/' . $redirect_item['origin'], | |
'/' . $redirect_item['url'], | |
0, | |
$redirect_item['type'], // http code | |
) ); | |
} | |
fclose( $fp ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment