When using categories in ExpressionEngine, a Category URL Indicator trigger word can be set to load a category by its {category_url_title}.
I would like to remove the category “trigger word” from the URL.
Here is what I have so far, with the trigger word set to “category”:
RewriteRule /products/(.+)$ /products/category/$1 [QSA,L]
I’m not an expert at writing regular expressions, but I do a little. I’m 99% sure my RegEx is fine, however when trying to use it as a RewriteRule in my .htaccess file, I’m getting a 500 error.
I’m sure it’s something stupid, but for some reason I’m not seeing my mistake. What am I doing wrong?
Update: Adding a ^ to the beginning of the RewriteRule fixed the 500 error.
RewriteRule ^/products/(.+)$ /products/category/$1 [QSA,L]
This is not safe. Take:
The regex group matches
a.It will be rewritten to:
which the regex matches again (this time, the group matches
category/a). Guess what will happen.You want
/products/from the beginning of input if it is not followed bycategory/, which means you want a negative lookahead. Also, theQSAflag is of no use, you don’t have a query string to rewrite (QSA stands for Query String Append):Another way to use it (and which I personally prefer) is to use a
RewriteCondprior to the rule: