I would like to ask a question to understand how Apache processes rewrite the rules specified in the .htaccess file.
On my site, I used the classic organization of pages in categories, each category of which has more than one section:
http:
However, there are no html pages, everything is processed by the code in pages.php. Using a simple rewrite rule, URLs like the ones above map to:
http:
I decided to rename the section from section1 to section1-xxx . To serve requests for the old name (section1), I added a simple rule to map section1.html to section1-xxx.html .
The first rules I added to .htaccess were as follows:
R 1
RewriteRule ^CAT1/section1.html$ CAT1/section1-xxx.html [NC]
where CAT1 is the name of the category.
R 2
RewriteRule ^CAT1/(.*).html$ pages.php?cat=CAT1&page=$1 [L,NC]
My idea was to use R1 and then R2. However, when these rules apply, I end up with an inexplicable (for my brain) URL.
When requesting the next page
http:
The URL is first converted to
http:
then in
http:
Out of curiosity, I added the L flag (flag) to rule R1:
RewriteRule ^CAT1/section1.html$ CAT1/section1-xxx.html [L,NC]
and it worked fine. Now http://www.mysite.com/CAT1/section1.html is submitted via:
http:
Now the questions are:
- Why did I get this URL before adding the L flag to the R1 rule?
- The L flag should indicate the application of the matching rule and the termination of the use of other rules. However, if the L flag is set, both R1 and R2 apply. Why?
Thank you for your time.
Regards, A.