Previously added WP mod_rewrite rules should be overwritten by CP rules.
Current behavior
I have migrated a test install from WordPress to ClassicPress.
I then reset the permalinks but noticed the WP rules were still present in htaccess.
See attached.
Steps to reproduce
Install WordPress
Migrate to Classicpress
Reset permalinks
Context
Although the migration is working perfectly fine, my spidey sense/ OCD dictates the WP rules should have disappeared.
Iâve seen it. Didnât break anything. Looking at the code I think it looks for the #Begin and #End tags to do a hard flush and rewrite or not. So if it finds #Begin WordPress it leaves that there and writes the #Begin ClassicPress rule set. Have to do more tests to see if it happens on migration and/or just when updating permalinks.
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
# 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
# Wordfence WAF
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
# END Wordfence WAF
# BEGIN ClassicPress
<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 ClassicPress
So when I change the permalinks to plain it removes the ClassicPress but leaves the WordPress rules. The site doesnât use the WordPress rules however so again doesnât break anything.
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
# 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
# Wordfence WAF
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
# END Wordfence WAF
# BEGIN ClassicPress
# END ClassicPress
Itâs more interesting to me.
For me, the hosting has added additional rows to the WordPress part. But not for the part about ClassicPress. I guess the reason is the AutoSSL in C Panel.
Iâm getting involved in the discussion to say that the WordPress section may have been modified by some hosting companies.
Thank you for your efforts to have an alternative to WordPress.
@KokoFresha that is interesting, which hosting provider is this?
I think putting these rules inside the ### WordPress section is not a great idea on their part, it would be better placed in a separate section. Otherwise, I am not sure why they wouldnât just be overwritten when WordPress refreshes its rules.
Anyway the fact that sometimes this section doesnât look as expected is a good thing to keep in mind here when testing, so thanks for bringing it up.
The provider is Superhosting. The best provider in Bulgaria.
I just asked for some information from the support.
Their answer is, âThese are system rules for AutoSSL to work properly.â
I suppose they update .htaccess before each renewal of the certificate, which is automatically 3 months. Since I was migrating to ClassicPress after the last renewal, the part for Classicpress was not affected.
These rules are added to all my Rewrite rules - bad bot, https redirects, access deniedâŚ
I was also surprised at this editing, but it is good to know that some suppliers may use such an approach.
It seems to me to be useful for future updates of ClassicPress.
Same in my multisite install. Since it works fine I didnât consider that as an issue however. I noticed my hosting modified the wp part.
I have avoided touching it because I wasnât sure it was OK deleting wp part.
Not seeing both WordPress and ClassicPress rules after migration; just ClassicPress.
Also, rules that existed outside the # BEGIN / # END lines were undisturbed (where my webhost added rules related to AutoSSL).
So, seems to work as expected. (I did not visit and resave the rewrite rules, BTW)
I have just tried this on one of my own sites and can confirm this behavior. Migrating from WP to CP has no effect on the .htaccess file. But saving permalinks adds the CP code to the end of that file while leaving the WP code intact.
Ah, ok. Perhaps what I mentioned only applies after permalinks have been saved once. I only need to visit the page to refresh the rules at that point; no save required.
But visiting the page to refresh the rules is not exactly an intuitive thing. It never occurred to me to do it on the sites I migrated. I think it should be automatic and overwrite the WP rules.
Thanks for testing this everyone. ClassicPress is looking for a # BEGIN ClassicPress section in the .htaccess file, and if it doesnât find that, it makes a new one.
Trying to flush and update the rewrite rules during migration doesnât seem like a good idea, it is just one more thing that isnât strictly necessary but could go wrong.
We can get rid of the duplication though. If ClassicPress saves its rewrite rules, and there is already a # BEGIN WordPress section, we can replace it instead of adding a new one.
Iâm happy to get this change made in ClassicPress v1 if we can get it implemented and tested. I donât think we should hold up the release for this change but I think itâs something we should fix eventually.
Is this on migration, James, or when you save the permalinks page? Itâs just that none of the sites I checked have any mention of ClassicPress in .htaccess after migration.
Does it matter if they are labelled as WordPress rules? What would be wrong with simply replacing the word âWordPressâ with âClassicPressâ in .htaccess and keeping all the current rules intact. From the OPâs example it looks like the rules are the same.
When you save the permalinks page from ClassicPress.
Not really, it doesnât break anything This is probably still what will happen when youâve migrated a site, but you havenât re-saved the permalinks yet.
What would be wrong with simply replacing the word âWordPressâ with âClassicPressâ in .htaccess and keeping all the current rules intact.
This is basically what Iâm thinking we can do, but it will happen the first time ClassicPress re-saves the permalink structure / rewrite rules.
The only thing I didnât really understand was this talk about âresaving the permalinks pageâ. Why would anyone even do that? I am migrating existing WP sites that are already set up the way I want. It never occurred to me to go back in and save the same settings again.