Support » Fixing WordPress » 404 when editing a post with hyperlink

  • Resolved Michael Nelson

    (@mnelson4)



    This is a doozy, you’ll like it.
    Since about a week ago, when I edit a post, if that post contains a hyperlink (eg <a href="...">...</a>") when I update it, I’m sent to the 404 “Page not Found” page, and the post is NOT saved. Here’s a video: https://drive.google.com/file/d/1OQZ9k5f_jxbxsT4SEyD-pH28FSIMoQlT/view.

    I added some debug code to wp-admin/post.php to see if it’s getting called when the POST request is sent, and it isn’t. The request is somehow going to index.php, and there’s no URL rewrite for that, so it becomes a 404.

    I was suspicious that the plugin “Auto Affiliate Links” was the culprit (https://wordpress.org/plugins/wp-auto-affiliate-links/), because it changes hyperlinks to be affiliate links, and was having some error. But the error still happens when after I’ve deactivated the plugin.

    In fact, I temporarily switched the site to a use a fresh DB (all default settings), with default (twenty seventeen) theme, NO plugins active, and I still get the same problem. However, when I copied the directory containing WordPress’ files to a local copy (running VVV), I did not get the issue.

    So it seems very unlikely that it’s a plugin causing the issue, because the issue persists with all plugins deactivated, and even on a fresh DB (so they couldn’t have changed something in the database). The only way a plugin could be the culprit would be if they changed WP core FILES, right? But if that were the case, I would have expected to reproduce the issue when using those same files on my local VVV site. Right?

    I don’t think it’s a WP configuration issue because I get the same issue on a fresh install of WP.

    I was suspcious that maybe it was a .htaccess issue, but here’s my vanilla htaccess file:

    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    

    Looks pretty regular, right?

    The last possibility, I think, is the hosting company, uniserve (https://www.uniserve.com/) has something running on the webserver that’s intercepting the request for /wp-admin/post.php and instead sending it to /index.php, but only when the post content has a hyperlink in it. Maybe it’s an attempt at blocking some spammers from creating posts with backlinks to their site or something.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi, Michael Nelson, & welcome. May we please see your .htaccess file if you have 1, &/or any mod_rewrites that may be occurring on your site?

    Hi Jackie, thanks for thd reply. I actually already put the contents of the htaccess file in my original post above. And it’s a shared server and I don’t have access to any the Apache config etc. or where else would could mod rewrites be contained?

    O, duh, MichaelNelson, I didn’t even see that. Humblest apologies. Could you please tell us how your permalink structure is set? Could you please change your permalinks to the default structure, save your settings, then change it back & resave?

    Also, when you’re adding a link, are you using the visual or text tab on the editor?

    Also, MichaelNelson, can you access the .htaccess file a level above your web root folder? Have you tried changing wp_debug from ‘false’ to ‘true’ then tried to save a post w/a link & seeing if any errors are thrown? Lastly, does your hosting provider’s control panel have an aplet wherein you can read your site’s error logs, or are there any error_log or error.log files in your web root or other WordPress subdirectories that might be relevant?

    > Could you please tell us how your permalink structure is set?

    Right now, it’s /%postname%/.

    When I change it to the default, I get a different error. When I save the post, I immediately get an error screen saying “Forbidden You don’t have permission to access /wp-admin/post.php on this server. Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.”, eg https://drive.google.com/a/eventespresso.com/file/d/14Kzkm14AJ5e7XXKCAuR-4NHBlcOZKdJ_/view?usp=drivesdk

    > Could you please change your permalinks to the default structure, save your settings, then change it back & resave?

    Good suggestion but that didn’t fix it.

    > Also, when you’re adding a link, are you using the visual or text tab on the editor?

    I’ve been using the text tab, but when I switch to using the visual tab I also get the error.

    > Also, MichaelNelson, can you access the .htaccess file a level above your web root folder?

    You mean the folder that CONTAINS the public_html (where public_html contains wp-admin etc) right? There was no .htaccess file there, but when I add one with random content, it caused an error on the server, so I’m pretty sure that means apache is picking up that .htaccess file and using it. So I’m pretty sure that means “yes, I can access the .htaccess file a level above the web root folder”.

    > Have you tried changing wp_debug from ‘false’ to ‘true’ then tried to save a post w/a link & seeing if any errors are thrown?

    Yes I set WP_DEBUG to true but am not seeing any error text when saving the post with a hyperlink in it and getting the 404.

    > Lastly, does your hosting provider’s control panel have an aplet wherein you can read your site’s error logs, or are there any error_log or error.log files in your web root or other WordPress subdirectories that might be relevant?

    Yes we can see access logs and error logs.

    When I have the default permalinks, these are the access logs when I try to save the post with a hyperlink in it:

    > 96.54.153.82 – – [19/Feb/2018:09:10:40 -0800] “POST /wp-admin/post.php HTTP/1.1” 404 – “http://mariakoropecky.com/wp-admin/post.php?post=719&action=edit” “Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0”

    In the error log, I see

    > [Mon Feb 19 08:58:02 2018] [error] [client 96.54.153.82] File does not exist: /home/vhosts/mariakoropecky/public_html/403.shtml, referer: http://mariakoropecky.com/wp-admin/post.php?post=719&action=edit
    “[Mon Feb 19 08:58:02 2018] [error] [client 96.54.153.82] File does not exist: /home/vhosts/mariakoropecky/public_html/403.shtml, referer: http://mariakoropecky.com/wp-admin/post.php?post=719&action=edit

    Michael Nelson, I’m assuming your links don’t look like:

    as in your previous post, because there’s an extra quote mark that doesn’t belong there. Do you perchance have WordPress set to close tags automagically? Also, you said this started occurring about a week ago. Can you think of anything that may have occurred at that time, ie, plugin installation/deletion, update, etc, that could’ve coincided w/this?

    Have you checked w/Uniserver to see if they’re receiving any mod_security rules that are firing on your server?

    You’re right. It’s a duzy. I’d like it if it werent for the fact it’s causing you a headache.

    I guess there’s 1 other thing we should discuss at this point. I’m completely blind & have been for awhile now. Your visuals would surely help other forum volunteers, but, since you appear to be stuck w/me, if you might be so kind in future to give me a bit of description of the visuals, that would really really help. I apologize for the inconvenience. You’re obviously experiencing enough inconvenience already, & I certainly don’t mean to add to it.

    as in your previous post, because there’s an extra quote mark that doesn’t belong there.

    Oh that extra quote was just a mistake pasting into here- no the original hyperlink in the post does not contain that extra quote mark.

    > Also, you said this started occurring about a week ago. Can you think of anything that may have occurred at that time, ie, plugin installation/deletion, update, etc, that could’ve coincided w/this?

    I asked the site owner and they said no.

    > Have you checked w/Uniserver to see if they’re receiving any mod_security rules that are firing on your server?

    I’m trying to get in touch with them, but as usual they’ve previously been pretty deflective. Also, I wasn’t aware of mod_security, but that sounds like a very likely culprit. I’ll follow up with them.

    > if you might be so kind in future to give me a bit of description of the visuals

    Oh sorry, sure. So far I’ve mostly been describing what I’m seeing, and then provided a supplemental visual.

    I think the 403 error I’m getting when saving the post with permalinks turned off is a big clue. Ie, the error said “Forbidden. You don’t have permission to access /wp-admin/post.php on this server. Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request. That means something is preventing the file wp-admin/post.php from being read (but only on a POST request with a hyperlink in the text; otherwise I can request that file just fine), and there’s also an error while recording the error, so there’s no trace of the error in logs etc.

    Actually, I think I was doing pretty well figuring it all out. I just didn’t want to miss something if I could help it, Michael.

    I figured the stray quote was likely a pasting error, but you know what you do when you assume. So I thought I’d point it out just in case it was relevant.

    I think the forbidden error is pretty telling, & I suspect perhaps some changes made to your hosting provider’s mod_security rules may be the culprit. Again, I’ll ask if WordPress is set to close tags automatically, because if so, then closing them manually may (or may not) create problems. But I think your next call is to the hosting provider, asking them to check on whether mod_security is firing on some rules.

    If the hosting provider doesn’t/can’t help, I’ll be glad to offer you a staging area on my server in order to clone the site & see if you’re receiving similar results, if that’s of interest. If no problems occur, then we pretty much know it’s a hosting issue. You’ve actually kind of done that already on your local box, but it might be something to consider nonetheless.

    You’ve done a really great job troubleshooting this, Sir, & I do hope that once this is all said & done, you’ll think about joining the volunteers here to lend a hand to those who need it. We could always use more help. & you’ve already got a friend on here so it’s not like you won’t know anyone, which can always be a bit intimidating :).

    Thanks Jackie, I talked with the hosting company about temporarily disabling, or at least investigating, the modsecurity issue, and they were basically unwilling to budge. Their rationale was nobody else reported the issue so it must not be real. But they also haven’t tested to see if they reproduce the issue. So I think I’m going to recommend we move to a different host.

    So I’m satisfied to report this is an issue with modsecurity done by the host.

    Thanks for being a sounding board!

    And thanks for the invitation to help out in the support forums. My job gives me a few hours a week to contribute so I’ll more seriously consider spending some of it here.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘404 when editing a post with hyperlink’ is closed to new replies.