Plugin continuously rewrites .htaccess file
-
Hi,
After installing the plugin we’ve noticed that our .htaccess file is being continuously written and overwritten (most of the time with correct content, but very often with duplicated rules). The issue stops the moment the plugin is deactivated.
I’ve been able to track it down to the the flush_rewrite_rules call on wp_loaded filter hook in includes/rewrites.php file.
Can you please check it out and maybe find a different hook for it (e.g. so it runs just once on activation or something similar)?
Thanks π
Take care,
Alex
-
Hi Alex,
Thank you for your suggestion. I think it is a good idea to only trigger the flush in plugin activation. Better yet, it would better to keep running it on wp_load but only run the rewritten if it does no exist.
As for the issue where your .htaccess file is being written to, WP OAuth Server does not write anything to the .htaccess file. This could possibly be due to a conflict with another plugin. Could you provide a list of plugins you had activated when you was seeing your .htaccess file being written to?
Thanks
Hi Justin,
Thanks for the reply.
Not sure a list of plugins will help as it’s a lengthy one:
—
BAW Manual Related Posts
Category Order and Taxonomy Terms Order
Chartbeat
Co-Authors Plus
Google Analytics by Yoast
Google Analytics Dashboard
Insert Pages
Intercom for WordPress
Liveblog
NextGEN Gallery by Photocrati
NextGEN Gallery Sidebar Widget
NextGEN Pro by Photocrati
Optimize Database after Deleting Revisions
Post Date Change Redirection
Post Types Order
Recently Registered
Regenerate Thumbnails
Related Posts Thumbnails
Rename wp-login.php (unmaintained)
Reports Plugin
RSS Icon Widget
s2Member Framework
Search & Filter
Send email only on Reply to My Comment
Sharing Tracker
TablePress
UCN newsletter builder
WordPress OAuth Server
WP Currency Converter
WP REST API
WPJobBoard
—And for what it’s worth, I wouldn’t keep it running on wp_load. No offence, but too many plugins keep too much stuff running on init and wp_load just because they can’t be bothered to find a suitable place for it π
I’ll keep that wp_load hook disabled and have the rewrite rules added to .htaccess (via non_wp_rules) for the time being.
Hope you can figure it out though. Thanks π
Take care,
AlexHi Alex,
No offensive taken. If you would, please provide an action to run the rewrite rules that you feel would be better. I have noted that it should not run on every load. I am always open to opinions and idea’s that better the plugin as a whole.
Looking trough your plugins list I noticed that s2Member is installed. WP OAuth and s2member does have known conflicts and may be where some issues are arising.
Hi,
Here’s the
.diffof what I’ve settled on for our site – would be nice to see something similar (I’m fine with it not using non_wp_rules too π in one of the future releases.diff -r -w oauth2-provider-3.1.7/includes/rewrites.php oauth2-provider/includes/rewrites.php 17,23c17,23 < function create_rewrite_rules($rules) { < global $wp_rewrite; < $newRule = array('oauth/(.+)' => 'index.php?oauth=' . $wp_rewrite->preg_index( 1 ) ); < $newRule += array('.well-known/(.+)' => 'index.php?well-known=' . $wp_rewrite->preg_index( 1 ) ); < $newRule += array('wpoauthincludes/(.+)' => 'index.php?wpoauthincludes=' . $wp_rewrite->preg_index( 1 ) ); < $newRules = $newRule + $rules; < return $newRules; --- > function create_rewrite_rules($wp_rewrite) { > if (!defined('DEACTIVATING_OAUTH2_PROVIDER') || !DEACTIVATING_OAUTH2_PROVIDER) { > $newRule = array('oauth/(.+)' => 'index.php?oauth=$1' ); > $newRule += array('.well-known/(.+)' => 'index.php?well-known=$1' ); > $newRule += array('wpoauthincludes/(.+)' => 'index.php?wpoauthincludes=$1' ); > $wp_rewrite->non_wp_rules = array_merge($newRule, $wp_rewrite->non_wp_rules); > } 74c74,75 < add_filter( 'rewrite_rules_array' , array($WO_Rewrites, 'create_rewrite_rules' )); --- > > add_action( 'generate_rewrite_rules', array($WO_Rewrites, 'create_rewrite_rules')); 76d76 < add_filter( 'wp_loaded' , array($WO_Rewrites, 'flush_rewrite_rules')); diff -r -w oauth2-provider-3.1.7/wp-oauth.php oauth2-provider/wp-oauth.php 54a55 > register_deactivation_hook(__FILE__, 'wo_plugin_deactivate'); 70a72,75 > > $wo_rw = new WO_Rewrites; > $wo_rw->create_rewrite_rules(); > $wo_rw->flush_rewrite_rules(); 73a79,85 > function wo_plugin_deactivate() { > if (!defined('DEACTIVATING_OAUTH2_PROVIDER')) { > define('DEACTIVATING_OAUTH2_PROVIDER', true); > } > global $wp_rewrite; > $wp_rewrite->flush_rules(); > }Thanks π
Take care,
AlexAlex,
Thanks for the suggestion and the patch. I also think non rewrite rules would be beneficial for speed as well as obvious handling reasons.
Thanks again
Hi,
I have the same problem as Alex, on my website.
I’ve been able to track it down to the the flush_rewrite_rules call too, and that led me on this support page.To reproduce the issu :
– WordPress 4.3.1 with permalink set to “post name” and default theme
– Wpml 3.2.7 with english as default language and another language ( FR for my case )
Language URL format set to “directories” in languages settings
– Json Rest API 1.2.3
– And of course WP OAuth Server 3.1.7 ( but it was the same with 3.1.8 )If all of that is set, then the htaccess keeps being written and overwritten.
For exemple, if i go the a translated page like test.com/fr/contact, the htaccess is overwritten with /fr/ for the RewriteBase.
Then every page of my website produce a 500 Internal Server Error until i load any admin page and then i can navigate the website again until i go to a translated page…The patch suggested by Alex is working for me except those 3 lines that i commented :
$wo_rw = new WO_Rewrites;
$wo_rw->create_rewrite_rules();
$wo_rw->flush_rewrite_rules();Don’t hesitate if you have any question Justin i would be happy to help !
Take care
ThibautThank you for letting us know that you are experiencing the issue as well. In version 3.1.9, we are moving the rewrite to only happen if an rewrite is not found.
If this works as expected, then we will ensure it only rewrites 1 if needed. If there is another plugin causing WP OAuth Server to rewrite, we will investigate. If the issue is indeed the WP OAuth Server we will be happy to fix. If another plugin is causing WP OAuth Server to do the rewrite, we will contact the other plugin author(s) and find out more information.
Thanks again.
The topic ‘Plugin continuously rewrites .htaccess file’ is closed to new replies.