2

For couple of days I am experiencing issues with modifying some of my posts. When I try to modify the content of post, I get 404 error, redirecting me that page is not found.

Doing Google research, with all basic tests, clear cache, browser, enable/disable plugins, changing permalinks, etc, I've found this on WP forum, saying that Apache's ModSecurity is causing issues:

https://wordpress.org/support/topic/clicking-the-post-draft-button-sometimes-redirects-a-404-not-found-page/

https://wordpress.org/support/topic/404-page-not-found-when-savingupdating-a-postspage/

However, this doesn't work for me, because I don't option in Cpanel to disable ModSecurity - disabled from hosting company.

I've got this response from them:

Mod_sec is an important server level security feature. We are not going to disable mod_sec.

Certain WordPress posts (such as ones that appear to be SQL injection attacks) may trigger mod_sec, but it certainly is not all WordPress posts.

Is there any work-around to solve this? I have a SSH access, bit limited, but may helps.

Also, I am not 100% sure about - but I've noticed that I can(haven't test all) update my old posts.

Posts that are ~ 5-6m old are throwing 404 error. WP version is 4.7.2

EDIT

The only option I have now, is to do a backup of production site, load on my locahost, update posts and push it back to production.

However, this isn't convenient at all. :( Does anyone have a solution?

Please help! Thanks!

5
  • Does your hosting provide remote access to your MySQL database? or it only has local access?
    – Johansson
    Commented Feb 18, 2017 at 18:25
  • @JackJohansson Yes, there is an option for remote SQL
    – fugitive
    Commented Feb 18, 2017 at 18:28
  • Try this science-fiction answer that i posted for you. It saved me a while back from an Apache limitation.
    – Johansson
    Commented Feb 18, 2017 at 18:43
  • This is a problem on your hosting side, probably misconfiguring some aspect of mod_security. Commented Feb 19, 2017 at 15:32
  • You mention this is happening with older posts... is there some kind of content in the older posts that is not in the new ones? Have you tested publishing the old content in a new post? This may help determine whether it is some specific content triggering mod_security or something else (post meta?)
    – majick
    Commented Feb 19, 2017 at 15:41

4 Answers 4

2
+100

If you have access to remote MySQL, this MIGHT help you. I've done this a while ago when i had another issue with my hosting provider.

Take a full backup of your WordPress files, but not your database. Copy them to your localhost. Now, instead of using a local database, in your wp-config.php file, set your database to the remote database of your online website (obviously make a backup first).

define('DB_HOST', 'YOUR REMOTE DATABASE');

Now, force the local installation to use the localhost as Site URL and Site Address, by defining these in wp-config.php :

define('WP_SITEURL', 'http://localhost/');

define( 'WP_HOME', 'http://localhost/' );

Now, you can disable mod_sec on your local Apache web server and update your posts.

PS: I did not try this with mod_sec, and i do not guarantee this to work for you. I don't even know if this is officially confirmed, but since i did this myself and worked, i considered sharing it with you (since it was too long to post as a comment). I don't even know if it's secure or not.

However, be warned about hardcoded URLs and uploads, because these will cause an issue if you are trying to upload files while on localhost. But modifying the content itself, shouldn't cause a problem.

PS 2 Please be gentle with your downvotes. Although it may look more like a science-fiction project, but it personally worked for me, so i can't accept people telling me this will never work.

5
  • I like the idea. Allow me some time to try, because my network configurations, firewalls, etc. And surely won't downvote, I'm not a j* ;-) Thanks!
    – fugitive
    Commented Feb 18, 2017 at 19:03
  • Sure, btw i didn't mean you about the downvote, but there are many visitors who downvote just because they don't like it at the first spot. You might also be able to use rewrite if you are still redirected to original domain. My knowledge about rewriting is limited, but there are plenty of users here that can help.
    – Johansson
    Commented Feb 18, 2017 at 22:00
  • Man, this did a trick, I knew it would since I liked the idea. It is much slower to update remote DB - but as I am evading modsec this way - I am happy. :) Can you advise, can I break my production somehow? By now I am only updating my posts on remote DB, I don't think anything can go wrong, right? Bounty is yours - congrats and thank you again! :)
    – fugitive
    Commented Feb 19, 2017 at 20:52
  • 1
    Of course, with this method you cannot do media upload. Not only that the upload will not happen to your server, but also upload will put wrong URL in database. You'll have to take many extra steps to avoid database errors such as this. Not to mention the possible security issue you may face because of accessing database like this. If you have problem with the current host, it's better to change the host than doing these sort of work arounds. Your only safe option is to actually debug the mod_security problem and solve it. Otherwise change hosting company.
    – Fayaz
    Commented Feb 19, 2017 at 22:40
  • 1
    You are welcome, sometimes silly ideas work xD Unless you don't have any hardcoded data, such as links saved as localhost/blabla/ you won't have any problem. As long as i know, WP saves images relatively, such as /2017/2/myImage.jpg. As a matter of fact, your website is just a computer like yours, accessing database, so there isn't much difference between reaching the database via your own pc or the host itself.
    – Johansson
    Commented Feb 20, 2017 at 9:20
3

there's no guaranteed solution from me but a few point may help you towards the solution.

1: double check your .htaccess file. and paste below code into it.

# 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

2: check your database for errors and perform a db repair and table optimization

3: try changing the directory and file permissions & change them to 755, 775 or even 777 for a while. also change htaccess file permission to 777 for a short time.

4: double check the URL of post edit screen and make sure the URL looks like below.

http://yourdomain.com/wp-admin/post.php?post=1&action=edit

where post=1 is the post ID and action value must equal to edit.

5: i think you already have changed permalink structure from settings since it's very basic thing and works for frontend but try changing them again to Numeric.

6: make sure that you have not modified any core WordPress file or filename.

7: WordPress provides an action hook named save_post which you can use to test post data for clarification. find out more here

8: finally maybe reversing the core WP version to older one might work?

1
  • tried to disable modsec via htaccess, but like I thought - they disabled overriding in Apache. For the rest - tried everything of those and checked before. Thanks for help!
    – fugitive
    Commented Feb 18, 2017 at 19:07
0

Usually, the hosting company can disable specific mod_security rules that may be affecting your hosting account. I've run into this problem before, it's usually a plugin that causes the issue.

Try disabling plugins and updating the post again?

1
  • I've already said that I tried that, this is an issue with Modsec, not with plugins/cache/themes etc.
    – fugitive
    Commented Feb 18, 2017 at 17:47
0

Go into the admin panel and reset your permalinks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.