For some test purposes I am trying to rewrite URL using .htaccess. I am using two different scripts in order to test two different structures of URL.
In public_html is folder cms. In that folder are php scripts number_item.php and name_item.php
(1) number_item gets product from db based on id (number) + product name (letters, numbers and dashes) and URL looks like this
www.example.com/cms/12345/item-name
RewriteCond %{THE_REQUEST} \ /www/number_item\.php\?id=([0-9]+)&([^&\ ]+)
RewriteRule ^ %1/%2? [L,R=301]
RewriteRule ^([0-9]+)/(.*)$ number_item.php?id=$1&$2 [L,QSA,NE]
(2) name_item gets product from db based on unique name (letters, numbers and dashes) and URL looks like this
www.example.com/cms/item-name
RewriteCond %{THE_REQUEST} \ /www/name_item\.php\?un=([^&\ ]+)
RewriteRule ^ %1/? [L,R=301]
RewriteRule ^([^&\ ]+)/(.*)$ name_item.php?un=$1 [L,QSA,NE]
Issue that I am facing is with the second case (name_item) , rewrite works just fine and item page loads normal but I get series of 404 errors on site generally
since rule actually affects on other folders that are in cms folder, treats them like text.
Question is, is there some way I can restrict rule only to name_item.php or exclude other files and folders in cms folder or any other better solution.
Thanks for help