When somebody tries to open the product display page for the product which is unpublished, it results in the access denied 403 page being shown.

I want to display a message ("This product is not available as of now, check other products.") instead of showing 403 page.

3 Answers 3


You could add a view as the error page.

Add the view with page (with appropriate path) and attachment as your error page. Filter it on your Product display, pass in the nid as contextual filter and be as creative as you want. The attachment can show the details for the Product that is no longer available, the actual page view can show similar products as alternatives etc. The not found for the contextual filter can be the generic 403 for anything other than products.

Then add the path of the view to the 403 error page setting at admin/config/system/site-information


Have a look at my answer to the question about "How to make the permissions of a module more granular?". It uses (only) the Rules module, for which this is the summary of the included rule:

  • Rules Event: Drupal is initializing.
  • Rules Conditions: Check if it is an anonymous user and verify if they try to visit some URLs they do NOT have access to.
  • Rules Action: Redirect those who meet the Rules Conditions to "some other URL instead", and display some informational message about it.

Start with adapting the URLs used in these Rules Conditions and Actions, and remove the 1st Rules Condition (about anonymous users). Then change the message to be displayed to your "This product is not available as of now, check other products.". With that, you might be close to what you're looking for.

Note: you might be able to further enhance this Rules Condition using some more appropriate Rules Condition that indicates "Product is unpublished" (though I don't know (yet) which one that would be).


If I were you, I'd create a menu item in a custom module for the site that you used as your custom 403 page. (You can configure this in your Site information settings form.) This menu item would look at the request path to determine if the user is seeing a 403 error because of an unpublished product display and return the product specific message based on that. Otherwise I'd fall back to the standard text (or perhaps a redirect to login).

This is the least intrusive way to manage your request without involving slower modules, unnecessary queries / render times, etc.

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.