Me mudé aprox 100 artículos de mi sitio web antiguo a uno nuevo. Quiero crear una redirección en el antiguo sitio de la cabecera, por lo que si la antigua dirección URL de un artículo en el que iba a ser visitado, el visitante debe ser redirigido a la nueva URL de dicho artículo.
Sin embargo, simplemente sustituyendo el dominio no hacer el truco, ya he cambiado el enlace de los artículos. Así que yo necesitaría un poco de "base de datos" (con matrices?) que pueda decidir si la URL tiene una redirección en la base de datos, como:
// "the old permalink" = "the new permalink"
$urlpermalink["article-cars"] = "http://NewWebsite.com/new-cars-article";
$urlpermalink["an-article-dogs"] = "http://NewWebsite.com/new-dogs-text";
$urlpermalink["old-text-trees"] = "http://NewWebsite.com/new-blogcontent-about-trees";
Así, por ejemplo, si un visitante "http://OldWebsite.com/article-cars" él debe ser redirigido a "http://NewWebsite.com/new-cars-article" porque es lo que la base de datos o matriz, dice.
Y así me podría algo como esto:
$visitingurl = $_SERVER[REQUEST_URI]; // Getting the URL the visitor is on now
foreach( $urlpermalink as $value ) { // For every entry in the database/array...
if (strpos($visitingurl, $urlpermalink) !== false) { // check if the visitingurl contains that (like "article-cars")
// The visitor is indeed on an old URL which is in the database/array, so let's redirect him to the new URL
header("HTTP/1.1 301 Moved Permanently");
header(url . $_SERVER['QUERY_STRING']);
exit();
}
}
Por supuesto, este código es totalmente equivocado, pero yo casi no tienen idea acerca de PHP, así que por favor podría ayudarme a resolver esto? (un JavaScript-solución está muy bien también, o htaccess, o lo que sea :) )
Muchas gracias!