Can anyone think of when it might be necessary to rewrite the request?

I found that one of the main reasons that overwriting .htaccess rule sets to do seemingly weird things is when Apache decides to try to apply them inside a subquery. This is to the extent that I now always use the [NS] flag in my rules or use the prefix rule

 RewriteCond %{IS_SUBREQ}%{ENV:END} t|1 [NC] RewriteRule ^ - [L] 

(The% {ENV: END} bit allows me to use E = END: 1 to do the same as the V2.4 END flag.)

My question is: can someone give me a good decree where I would not want to do this? (or, alternatively, where I would like to use special -U or -F special condition patterns).

I understand that there can be many that I did not think about, but the sign "A" goes to the first valid one.

+4
source share
1 answer

I would suggest that typical situations where you want to apply rewrite rules to subqueries more or less coincide with those where you used symbolic links inside your document root.

As a likely example, suppose you are using Server Side Includes and have a bunch of files scattered with suffixes such as .html , .shtml and .htm , and possibly some uppercase options. At some point, you decided to standardize the .html suffix and rename all your files accordingly. But you still have a bunch of legacy code and links that use other suffixes, and rooting them all will take some time.

In this case, you may need a rewrite rule as follows:

 RewriteRule ^(.*)\.s?html?$ $1.html [NC] 

By applying this also to subqueries, you guarantee that your server side will not break due to renaming.

+2
source

Source: https://habr.com/ru/post/1399642/


All Articles