Remember Me | register
Entries Blogs

Forums > Off Topic > Redirecting links

Fallen Aizen
Fallen aizen
Lvl: 4
Posts: 36
12/21/2007 12:56 PM EST

Hi,

Well, I was wondering if anybody knows how to make it so that if someone goes to my site and goes to the URL /2007/12/18/<post-name>, they'll be redirected to /12/18/2007/<post-name>.

I was thinking of altering the htaccess, but that seemed to have failed.  Now I think it has something to do with the PHP - which I can't seem to understand what I need to edit. So if possible, can anyone tell me what to edit?

hung
Hung
Lvl: 12
Posts: 462
12/21/2007 01:32 PM EST

How would you suggest the two permalink structures live in harmony? The rewrite rules would have to know the difference between a year and a month. That sounds like a job for a regular expression to me! Though I'm much too lazy and unmotivated to write one for you. But that hint should get you started!

I'll leave the rest as an exercise to the reader (man, I love that phrase!).

Fallen Aizen
Fallen aizen
Lvl: 4
Posts: 36
12/21/2007 01:41 PM EST

Um. I didn't get it at all :P

BUT, I was able to fix it via a PHP script.

In case anyone's wondering, this is what I did:
In the 404 php file, just add this (And checked if it works, of course):

<?php
$lolingquery = mysql_query("SELECT `guid` FROM `wp_posts` WHERE `guid` LIKE '%".$_SERVER['REQUEST_URI']."'"); // Check if it exists...
if(mysql_fetch_array($lolingquery)) { // If it's true...
$gcu = explode("/",$_SERVER['REQUEST_URI']);

header("Location: http://".$_SERVER['HTTP_HOST']."/".$gcu[2]."/".$gcu[3]."/".$gcu[1]."/".$gcu[4]); // This was able to redirect

}
?>

 

In case your host is like url.com/blog/, you'll probably have to change:

$_SERVER['HTTP_HOST']."/

to: 

$_SERVER['HTTP_HOST']."/blog/"

Anime-nano-rss