• nando99

    (@nando99)


    I currently have my links like this /%postname%/ –

    I’d like to change them to this /%post_id%/%postname%/ (because I read that it helps the site load faster).

    Is there way to have /%postname%/ links (on other sites) automatically redirect to the /%post_id%/%postname%/ links?

    Thanks in advance,

    nando

Viewing 15 replies - 1 through 15 (of 30 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    šŸ³ļøā€šŸŒˆ Advisor and Activist

    Not really, since that’s not a ‘standard’ format that can be grep’d or regex’d easily.

    Problem: Postname can be ANYTHING so while we can search for (.*), we would have to have a way to KNOW what Post ID == Postname, and that you can’t really do outside of WP.

    If you have a small number of posts you could manually do 301 redirects in your .htaccess (I did that for a site with 30 posts – not TOO horrible).

    Thread Starter nando99

    (@nando99)

    i have way to many posts to do that lol

    thanks tho… i thought there would be something i can put in the header that would just append the id to the url and redirect… i thought i read something like that some where…

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    šŸ³ļøā€šŸŒˆ Advisor and Activist

    You know, scrap all that.

    I use domain.com/YYYY/POSTNAME and I just went to domain.com/POSTNAME and it redirected me… So maybe WordPress is bloody brilliant! Try it.

    Thread Starter nando99

    (@nando99)

    just tried it, did NOT work… i was hoping tho lol

    wow theres has to be a way, hopefully lol

    You could add some conditional code to your theme’s header, but it might result in a few redirect loops.

    That conditional code would look something like the code posted at http://pastebin.com/vhQ3SghQ I think (I haven’t tested that code, and am working from memory at the moment).

    You would have to put that either at the very top of your 404.php template file (above the call to get_header() or at the very top of your header.php file; as it uses the PHP header() function, which will generate an error if any code or text is sent to the browser beforehand.

    Thread Starter nando99

    (@nando99)

    hey, thanks!!

    i put the code above get_header{} in my 404 template but unfortunately when i go to post that should give me a 404 (and then redirect) i get a blank white page….

    any additional help would be greatly appreciated since i’m pretty noob at this…

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    šŸ³ļøā€šŸŒˆ Advisor and Activist

    Curtiss, that is amazing! AWESOME!

    That means there’s a PHP error (probably something simple in the code I provided you). Do you have access to your error logs? If so, can you reload the page that causes the blank white screen, then check the logs and paste in the most recent errors?

    Thread Starter nando99

    (@nando99)

    isetenu, u got it to work?

    Thread Starter nando99

    (@nando99)

    heres the last minute of errors (a lot)

    [Tue May 17 15:01:20 2011] [info] [client 168.10.192.3] (32)Broken pipe: core_ou
    tput_filter: writing data to the network
    [Tue May 17 15:01:20 2011] [error] [client 168.10.192.3] PHP Fatal error: Call
    [Tue May 17 15:01:20 2011] [info] [client 168.10.192.3] (32)Broken pipe: core_ou
    tput_filter: writing data to the network
    utput_filter: writing data to the network
    [Tue May 17 15:01:16 2011] [info] [client 64.56.91.45] (32)Broken pipe: core_out
    put_filter: writing data to the network
    [Tue May 17 15:01:16 2011] [error] [client 64.56.91.45] PHP Fatal error: Call t
    o a member function get() on a non-object in /usr/local/apache228/htdocs/wp-incl
    udes/cache.php on line 93
    [Tue May 17 15:01:16 2011] [info] [client 64.56.91.45] (32)Broken pipe: core_out
    put_filter: writing data to the network
    [Tue May 17 15:01:16 2011] [info] [client 64.56.91.45] (32)Broken pipe: core_out
    put_filter: writing data to the network
    [Tue May 17 15:01:16 2011] [error] [client 64.56.91.45] PHP Fatal error: Call t
    o a member function get() on a non-object in /usr/local/apache228/htdocs/wp-incl
    udes/cache.php on line 93
    [Tue May 17 15:01:17 2011] [info] [client 64.56.91.45] (32)Broken pipe: core_out
    put_filter: writing data to the network
    [Tue May 17 15:01:19 2011] [info] [client 168.10.192.3] (32)Broken pipe: core_ou
    tput_filter: writing data to the network
    [Tue May 17 15:01:19 2011] [error] [client 168.10.192.3] PHP Fatal error: Call
    to a member function get() on a non-object in /usr/local/apache228/htdocs/wp-inc
    ludes/cache.php on line 93
    [Tue May 17 15:01:19 2011] [info] [client 168.10.192.3] (32)Broken pipe: core_ou
    tput_filter: writing data to the network
    [Tue May 17 15:01:20 2011] [info] [client 168.10.192.3] (32)Broken pipe: core_ou
    tput_filter: writing data to the network
    [Tue May 17 15:01:20 2011] [error] [client 168.10.192.3] PHP Fatal error: Call
    to a member function get() on a non-object in /usr/local/apache228/htdocs/wp-inc
    ludes/cache.php on line 93

    @nando99 – My guess is that you pasted the <?php and ?> tags inside of an area that’s already wrapped in <?php and ?> tags.

    Having two sets of <?php (opening) tags without a set of ?> (closing) tags in between will throw an error. I just tested it briefly on one of my sites and I didn’t get any PHP errors, so that issue is my best guess right now.

    Try removing the <?php and ?> tags from the code I posted on Pastebin and see if that fixes the issue.

    If not, try restoring your 404.php file to its original format, then copy and paste the whole block of code (including the opening and closing PHP tags) at the very top of your 404.php file (before the opening <?php tag in that file).

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    šŸ³ļøā€šŸŒˆ Advisor and Activist

    You could wrap it in is_404() and put it in your header.php file too.

    http://codex.wordpress.org/Function_Reference/is_404

    Thread Starter nando99

    (@nando99)

    this is how i have it:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Oooh. Just noticed what is probably causing the issue. The original code I provided was trying to feed an array of post objects into the get_permalink() function. Try the code at http://pastebin.com/ku8y1LgA and see if that fixes the issue.

    Thread Starter nando99

    (@nando99)

    I’m pretty sure I LOVE YOU right now… thanks!!!!!!!!!!!!!!!!!!!!!!!

Viewing 15 replies - 1 through 15 (of 30 total)

The topic ‘Changing Permanent Links’ is closed to new replies.