rewrite-command icon indicating copy to clipboard operation
rewrite-command copied to clipboard

`rewrite flush --hard` should create `.htaccess` if it does not exist

Open tomsommer opened this issue 5 years ago • 5 comments

Right now flush --hard returns success, but it actually fails if there is no .htaccess file.

flush --hard should create .htaccess if it does not exist

tomsommer avatar Oct 07 '20 07:10 tomsommer

A candidate for good-first-issue ?

janw-me avatar May 29 '22 19:05 janw-me

Yes, this seems like a bug.

However, the behavior would need to be aware of Apache vs Nginx as well. Creating an .htaccess file on an Nginx installation will not do anything. This should then throw an error too. The question is then whether we can reliably detect the hosting configuration that make use of a .htaccess file...?

schlessera avatar May 30 '22 11:05 schlessera

Maybe only do it if apache_modules: mod_rewrite. If you plan on writing to .htaccess, you should simply create it before doing so?

a touch() call before https://github.com/wp-cli/rewrite-command/blob/eaa88e5102eb81b1d230a385c42594d4506ecded/src/Rewrite_Command.php#L72 would do it

tomsommer avatar May 30 '22 13:05 tomsommer

As closely as I can tell this is currently working as desired.

After installing WP and configuring permalinks then deleting .htaccess and the running wp rewrite flush --hard the .htaccess file is recreated and exits with 0.

thomasplevy avatar Sep 11 '22 18:09 thomasplevy

Running rewrite flush --hard does create the .htaccess file if it doesn't already exist. I have run this command on both my local and remote setups, and I can confirm that it works as expected.

The only way that I can reproduce the issue is by removing the following lines from the ~/.wp-cli/config.yml, which is needed according to the command README.MD

apache_modules:
  - mod_rewrite

TremiDkhar avatar Oct 03 '23 19:10 TremiDkhar