Blank Pages When Posting Comments in WordPress?

I just resolved a problem on one of my WordPress based blogs where anytime a person posted a comment (logged in or not), they got a blank page. I tried all sorts of stuff to fix it. Turned off all the plugins, changed themes, you name it. I quickly discovered that when the comment form was submitted, none of the form variables were available in the wp-comments-post.php script. When this happens, the post can’t be queried from the DB and you fail on Line 11 (comment_id_not_found). A quick bit of debug code and I found NONE of the form variables were in $_POST. Not good.

I figured maybe something was in the theme headers, etc so I created a simple form with a couple variables that would post to wp-comment-post.php and it worked. Hmm. So I tried the other angle and created a comment post test script that dump the form variables and called it from my theme form file. The variables disappeared. Any theme, the variables vanished in my test script.

This had me totally confused. Why couldn’t I get basic form data into my form. Google returned a variety of ideas, but none that worked. Finally, I stumbled across a ticket for WordPress searching for ‘Blank Page on comments’ and someone had the same problem I did and for the same reason. It’s a doozy.

I’m one of those people who find the ‘www’ in URLs redundant. All my sites support them both, but from an SEO point of view, I’ve started ensuring www.mydomain.com permanently redirects to mydomain.com. When I setup this blog a few years ago, I had put in ‘www.baptiste.us’ in the blog configuration. A few months ago, I added a permanent redirect for www.baptiste.us to always go to baptiste.us. Everything worked as far as I could tell and since I don’t comment on my blog except to respond to new comments, well… That redirect and the blog settings BROKE the comments and I didn’t realize it for quite a while (I just figured nobody had anything to say :) ). Here’s why.

In WordPress theme comment files, the form ‘action’ variable includes the site url in front of wp-comments-post.php. So for my comment form, the action was set to http://www.baptiste.us/wp-comments-post.php, regardless of the theme I used. The problem is, the Permanent Redirect from www.baptiste.us to baptiste.us WIPES OUT the form variables, even though everything else seems to work. Silently. Now this may be due to session conflicts, etc, I’m not 100% sure.

But the solution was easy. I took out the ‘www.’ in my blog’s config so comment posts went to the ‘baptiste.us’ domain right away instead of www.baptiste.us and comments started working again.

Moral of the story - if you have a permanent redirect setup for your WordPress blog, be sure the desired domain is the domain set in the WordPress config. If you want everyone to end up at www.mydomain.com, you better have the ‘www’ in your WordPress config. If you want the www to always go away, make sure it’s not in your config either. Hopefully this post saves someone else the time and aggravation if they stumble into this trap.

So 3 days and nights of debugging on and off and all it took was updating two config variables in WordPress. Problem solved :)

ADDING: Beware of WordPress 2.3’s new Canonical URL feature. It’s a great feature, long overdue, but if you have redirects in .htaccess, you can possibly create a redirect loop. Lots of info on this feature can be found at Mark on WordPress.



31 Responses to “Blank Pages When Posting Comments in WordPress?”

  1. Wayde Christie Says:

    THANKYOU!!!

    I struggled with this myself, and your solution totally nailed it.

    Cheers!

  2. Paul Says:

    Thank you so much. You turned me down the right path. My provider blocks port 80, and I use no-ip with port redirect to update my changing address. Apparently, the ‘redirect’ caused WP to act the same way. To fix the problem I removed the port 8080 redirect and added the port to the URL in the options. Thanks again.

  3. Peter Boyd Says:

    Worked like a charm.

  4. Chimp Says:

    nice nice work, man. when i read the line “I’m one of those people who find the ‘www’ in URLs redundant.” i knew EXACTLY what caused my problem. after finding the solution, i went into my config screens, deleted the ‘www’ and now all is golden.

  5. Stiri Mondene Says:

    Thank you, it worked for me too!

  6. Embuck Says:

    Thanks it works perfect!

  7. sweeper Says:

    Thanks bro!! I’m so glad you took the time to write this post.

  8. Morgan Says:

    Wow. Thanks so much for that fix!!

  9. Arne Völker, Texter » Blog Archive » Sechs Monate ohne Kommentar Says:

    [...] Das war die Lösung. Danke dafür, [...]

  10. Tom Says:

    Thanks for the help. You just saved me a huge headache in a 30 second Google search and reading your post!

    Tom

  11. Rich Says:

    Thanks.. easy fix once the problem is figured out surprised this isn’t in the wordpress support as it seems pretty common

  12. Alex Weinstein Says:

    Thank you so much. I would have *never* thought to do this kind of fix… But it worked like a charm :) Uhhh, SEO can sometimes do evil things to ya..

  13. BlakkJakk Says:

    Damn. It doesn’t work for me. I did have a redirect for all traffic to http://www.blackjackskanz.com/index.php which I removed but no avail. I posted in a thread at Wordpress but I am at a loss.

    Site
    http://www.blackjackskanz.com/

    Forum Post
    http://wordpress.org/support/topic/87090?replies=29#post-610491

  14. Cobbi Says:

    That’s fine for me! Just need to make the invert thinkhing!

    Thanks for the brillinat aswer! I’ve opened a topic for myself on WPress foruns about this. As your aswer solves my question I’ll close it with a link to this page, if you don’t mind.

    :-)

  15. Chris Murphy Says:

    Ugh. what headache this issue has caused me — thank you for providing some isight into this.

  16. Curt Bianchi Says:

    Let me add my thanks. Stumbled across this web page via a Google search on “wp-comments-post.php fails”. You saved me a lot of time–and I had already spent a lot of time on this!

    Thank again,
    Curt

  17. Hani Says:

    Thank you for this post. It solved the same problem I had.

  18. CarrieMeyer.com » Comments Working Says:

    [...] blog. They work now so you can write as many comments as you’d like. This is how I fixed it: http://plugins.baptiste.us/wordpress/blank-pages-when-posting-comments-in-wordpress/ What a tricky [...]

  19. David Bradley Says:

    I don’t get it. Sometimes I get a blank page after attempting a test comment post other times nothing. In my logs I see thousands of 404s for the wp-comments-post.php page from my guestbook…

    I’m set up with http://www. in place everywhere it should be, so it’s not that…

    db

  20. daver Says:

    Wow, you just saved me another 2 hours of searching. Thank you. I owe you a beer or something

  21. Mike Baptiste Says:

    David - the 404s are spammers trying to spam your site. But intermittent blank pages seems odd. Its usually all or nothing. Anything in your error_log when you get a blank page? Sounds like some type of PHP problem.

  22. Niko Says:

    I found you with Google search. Thank you, now I have no blank page :)

  23. Cosmin Says:

    I have the same problem with a blog installed on a vpn network, where people access it via an ip… any thoughts on that?

  24. Mike Baptiste Says:

    If I had to guess, it’s a similar problem where they are using some type of redirect to get you to the final site. That’s the core problem - redirecting on a form submit often wipes out the form data.

  25. Roddy Says:

    Hi,

    I had the same problem, though the above solution wasn’t relevant. However, for anyone it helps: I managed to fix it by basically unchecking all boxes in options>discussion, and removing the lists of spam words to check, saving, and then replacing. I suspect there was a problem somewhere with the lists of spam words.

    Exactly what the problem was I don’t know, but it seems to be fixed now . . .

  26. Preetam Purbia Says:

    hi
    i am facing same problem can any body give me any other weblink
    where i can search out errors

    thanks

  27. omegh Says:

    it worked for me thaks saving my time :D

  28. * Home * Plugins * Downloads * Forums * About # Recent News * Redirecting Wordpress Feeds to Feedburner With mod_rewrite * Spam Karma 2 Can’t Die * On A New Host… * WordPress 2.2 and Xinha4WP * Things Aren’t As Dead As They Seem # Delivered by FeedB Says:

    [...] Blank Pages When Posting Comments in WordPress? [...]

  29. Justin Hopkins Says:

    Yeah, I just figured this out too. Mine was caused due to the ‘home’ and ’siteurl’ option in the database being set to http:// while my blog is under ssl, so https:// was needed. I used a MySQL query something like

    UPDATE wp_options SET option_value = replace(option_value, 'http://', 'https://') WHERE option_name = 'home' OR option_name = 'siteurl';

    Worked!

  30. Ryan Says:

    “I am posting this message the second time coz the first time it said..that you message has been flagged as spam and into moderation”
    Now the second time i am removing my website url from the website field and i am pretty much sure that the message would show up. I don’t know what is spam in this message..you see it for your self :-)

    There is no doubt that Akismet Marks Valid Comments As SPAM even googling it would show hundreds of bloggers being frustrated because of it. I spent my entire day today googling to check results for..
    1) my site wrongly spammed by aksimet
    2) my site wrongly spammed by wordpress
    3) my site wrongly flagged by aksimet
    4)Submit Blog Comments and Getting a Blank Page
    and various other terms and landed up to many blogs which had many bloggers complaining.

    See even here i have not added my website url while commenting coz when i do so my comment won’t show up..it gives a blank page what you are talking about so i know the problem and i read your entire post without missing anything.
    Akismet is hampering the blogging experience of many blog commenters who love to gel with others even though they are relatively new..this is really lame :-(
    I have even taken this whole issue to a next level..ya that is on Forums where it would gain a lot of exposure and maybe akismet would try to learn from it.
    If this post goes through with the my website url in the website field then dear webmaster please mark it “unspam”

    Thanks

  31. Web Design Says:

    Thanks for this nice post. It has solved my few problems.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>