Why does the program overwrite the entire site configuration file when saving settings, and why does it overwrite the rules I added myself?
When saving the settings, the site configuration file is rewritten in whole, and the manually added rules will disappear. This is because such directory-level configuration files have only one copy, and the program's write logic generates the entire template without reading and retaining the existing content. This is not because the configuration was written incorrectly, but because ownership has not been divided: both the rewrite rules generated by the program and the custom entries added by operations are placed in the same file, and either party's entire write will cause the other to lose.
Why do the rules disappear after a certain save
The typical phenomenon is: after changing the pseudo-static switch in the background or saving the site settings once, all the previously added access restrictions, redirects, and caching rules are gone. The corresponding fix can be found in the implementation of peers, and in the update record of PbootCMS V3.2.26, it is stated that the fix is for Apache misjudging the environment when enabling pseudo-static, causing the site directory configuration file to be overwritten each time it is saved.The value of this record lies in clarifying the cause: the program made a judgment error before generating rules, treating scenes that should not be rewritten as those that need to be rewritten, so every save triggers the entire writing.
The ownership issue of directory-level configuration files
The location of this type of file is under the site directory, the scope of action is this level and its sub-levels. It can carry a variety of content such as rewrite rules, access control, error page redirection, cache parameters, etc., where both the program and operations staff write. To avoid overlap, it can only be divided according to ownership:
- The part managed by the program: pseudo-static rewrite rules, path mapping bound to the site structure;
- The part managed by operations: manual redirection, access restrictions, security-related parameters, cache and compression strategies;
- Parts that both need to read but cannot write simultaneously: the behavior definition of the site root path, you need to confirm which party is the authoritative source before making changes.
How to separate the maintenance of both sides
There are three feasible ways to divide, and the common point is that the program only writes its own part
| The method. | Specific arrangement | Advantage | Points to note |
|---|---|---|---|
| Upper definition, do not place the lower layer | Write the operation and maintenance rules outside the main configuration of the site, and leave the directory-level files only for the program | Writing the entire program does not affect the operation and maintenance entries | Host configuration permissions are required, and it is often not available on shared hosts |
| Program writes an independent segment | Let the rewrite rule point to a separate file, and leave the operation and maintenance rules in the original file | Each side should write one, without overlapping | The program upgrade may revert to the whole write, and it needs to be rechecked |
| Manual entries are incorporated into program management | Maintain redirection and rules through the back-end entry, generated uniformly by the program | There is only one authoritative source, it will not be lost | Expressiveness is limited by the range of back-end functions |
AnQiCMS's pseudo-static rules are managed by the program, support custom pseudo-static URLs, the rewrite entries of the site are configured according to the rules instead of manual editing of directory files. Taking the third path is more stable, but the cost is that complex conditions depend on the back-end providing enough expressiveness.
Verification list after the modification is complete
The first step is to make a backup before making changes. The built-in backup capabilities of the program should cover data and static files, and without this step, it would be very difficult to recover from a single accidental overwrite. The second step is to copy the files in the current directory item by item into a list, save the settings first, and then compare them item by item to see which types of rules are missing, and determine the range of write coverage.The third step, use a test to confirm the trigger condition by not modifying any options and just saving: if the entire file is rewritten but the content is consistent with before, it means the write is unconditional;If the content changes, it means the program is regenerating according to the template. Step four, verify that the pseudo-static effect and manual entries take effect at the same time - request an address within a rule and an address outside a rule separately.Step five, record this difference in the deployment document, and run steps two and three again after each program upgrade, as the write range is a part that is easily changed by version updates.
Common questions
Can it be set to read-only to prevent the program from writing? Answer: The save operation will fail directly, as the program considers writing rules as part of the save process. A more feasible approach is to move the operation entries to a position where the program does not touch them.
Why would local be normal and online lose rules? Answer: Most differences are in environmental judgment. The program needs to know which server the site uses and whether rewrite is enabled, and when the judgment conditions are not met, it will go to the whole generated branch.
How to quickly recover after the manual jump is overwritten? Answer: Restore from backup, then change the jump to the upper configuration or the redirection entry provided by the background, to avoid falling into the file rewritten by the program again.