You have some errors in your regular expressions. Upload this check to your website if you want to play with them.
Sample ^((products/|product/|)PN[0-9-]+)/ does not match "URL / products / PN123" or "URL / product / PN123" or "URL / PN123" and returns PN123 due to embedded string matching and trailing slash. You can hide the product (s) / and make trailing / optional, as shown below.
I do not like to use! prefix in rule templates, especially when using grouped parts. Too easy to shoot in the leg. I prefer cond followed by a null rule or a negative result.
- Crash matching rules, though, may result in a postfix error, so I avoid them. The kernel starts re-launching the .htaccess files (because they are evaluated in the context of the "Per Directory") until a match occurs, so I find it LOT safer to always use the [L] flag
- Again, because of this loop, you need to make sure your rules end, and it is best to do this in a simple transparent way. In this case, you do not seem to want to rewrite the URIs that map to real files, so why not take the
-f test to the top, and all other rules can then assume that this condition is true. - Two search rules mean that the parameter cat = acc123 is used if the query for / acc 123 / etc and search = otherwise. Is this what you want?
- You need to enable the QSA flag if you do not want to ignore any existing parameters.
- The USCOR environment variable (I am capitalized) becomes REDIRECT_USCOR in the next pass, so this is what you are testing. I assume the rule follows the last cond
Introducing it all together:
Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase /
I'm not sure what you want to do with% {ENV: REDIRECT_USCOR} now without additional rules and logic, although it will be available in a script like $_SERVER["REDIRECT_USCOR'] .
source share