Need some php/database gurus for a custom redirect script…
-
Here’s what I need some help with currently, my blog’s old permalink structure was: blog.com/id/123 and now I’ve changed it to: blog.com/post-name. I’d hate to lose all incoming traffic to the old permalink structure and etc. Someone a few years ago helped me with this before, this post as reference.
Here’s the php/database codes from before…It was setup to redirect all incoming hits from: blog.com/post-name.htm to blog.com/id/123. For the wp-newuri.php file. Uploaded to the *root* of your domain.
<?php mysql_connect("localhost", "DATABASE-USERNAME", "DATABASE-PASSWORD") or die("connect failed"); mysql_select_db("DATABASE-NAME") or die("can't get to the database"); $result = mysql_query("SELECT ID FROM wp_posts WHERE post_name = '".addslashes($_GET['q'])."';"); while($row = mysql_fetch_assoc($result)) { foreach($row as $var => $val) { $post = $val; } } mysql_free_result($result); header("HTTP/1.1 301 Moved Permanently"); header("Location: /id/".$post); ?>
And the htaccess file information for was:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+).htm wp-newuri.php?q=$1 [QSA,L] </IfModule> # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
I need help changing the database call codes to locate the post_id then at end for redirection to send the people to the blog.com/post-name… So all blog.com/id/123 goes to blog.com/post-title. And the correct lines changed for htaccess mod rewrites. Anyone willing to help? Thanks…
Spencer
- The topic ‘Need some php/database gurus for a custom redirect script…’ is closed to new replies.