• Hello WordPress community,

    I recently updated my blog to WordPress 2.8.4. **

    Since then, a small script I was using to redirect my old Blogger site to the corresponding WordPress post broke. This script had been working for over a year, and I have not changed it.

    Here is the small PHP script:

    <?php
    
    require($_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php');
    $search_link = $_GET['p'];
    $vars = explode('/', $search_link);
    $num = count($vars) - 1;
    $filename = $vars[$num];
    $slug = str_replace(".html", "", $filename);
    
    $SQL = "SELECT posts.* FROM $wpdb->posts AS posts WHERE posts.post_name = '$slug' LIMIT 1";
    $posts = $wpdb->get_results("$SQL");
    
    if ($posts) {
    	foreach ($posts as $post) {
    		$found_link = get_permalink($post->ID);
    	}
    }
    else
    {
    		$found_link = "http://www.gangles.ca/";
    }
    
    ?>
    
    <html>
    <head>
    <title>Redirecting...</title>
    <script language="javascript"><!--
    document.location.href="<?php echo ($found_link); ?>";
    //--></script>
    
    <meta http-equiv="refresh" content="2;url=<?php echo ($found_link); ?>">
    
    </head>
    <body>
    <h1>Redirecting...</h1>
    <p>You can also proceed immediately to <a href="<?php echo ($found_link); ?>"><?php echo ($found_link); ?></a>.</p>
    <p>The main blog URL is <a href="http://www.gangles.ca/">www.gangles.ca</a>.</p>
    </body>
    </html>

    The problem seems to be that get_permalink($post->ID) is returning a 403 error. For instance:

    This redirect returns 403.
    This one does not, because get_permalink is not called.

    Is this a known issue? Does anyone know how I can correct my script? As I said before, it was working fine for over a year before I upgraded to 2.8.4.

    Any help would be much appreciated,
    Matthew

    ** In case this is relevant: At the same time, I made some minor modifications to my .htaccess file (to force trailing slashes and no “www”).

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    First set your desired permalink settings from wrodrepss admin area and then add this code in htaccess:

    <IfModule mod_rewrite.c>
    ErrorDocument 404 /index.php?error=404
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    Thanks,

    Shane G.

    Thread Starter gangles

    (@gangles)

    Hi Shane,

    My .htaccess file is already as follows:

    # Redirect www to non-www for root domain
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.gangles\.ca$ [NC]
    RewriteRule ^(.*)$ http://gangles.ca/$1 [R=301,L]
    
    ErrorDocument 404 /index.php?error=404
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    Thanks.

    Thread Starter gangles

    (@gangles)

    Does anyone else have any ideas why get_permalink() might be returning 403? Any help would be much appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Upgrade to 2.8.4 breaks get_permalink()?’ is closed to new replies.