I'm interested in redirecting to a 404 if no category exists at the URL, for example if category xyz doesn't exist at; mydomain.tld/shop/category/xyz

I'm using Switchee and a case value for category as follows;

{exp:switchee variable="{segment_2}" parse="inward"}
    {case value="category"}
        {!-- Redirect to 404 if no category exists here --}

Wondering if anyone knows how to do a redirect here if a matching category is not found?


2 Answers 2


Get Low Seg2Cat, make sure the Set All Segments setting is set to Yes, and then use something like this:

{if segment_2 == 'category' AND segment_3_category_id == ''}

...or the Switchee equivalent.

  • Awesome, thanks Low. Already had Seg2Cat installed so that was simples. :D Dec 5, 2012 at 11:02

I didn't have time to write this out before you chose Low's answer though, I will add it just the same for future reference:

{exp:switchee variable="{segment_2}/{segment_3}" parse="inward"}
    {case value="#^category/\S+$#"}
        your code....
    {case default="yes"}

This assumes you will always have something in segment 3 or else go 404

  • 1
    Low's version checks that a category actually exists though, rather than just that there is a string in segment 3 and that segment 2 is a category... think the OP needs a hybrid of both answers.
    – Tom Davies
    Dec 5, 2012 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.