Using the Unauthorized Redirect
MemberPress' Unauthorized Redirect option gives you a way to redirect unauthorized users to a specified custom page when they try to access the protected content on your site.
This allows you to provide additional information to your site visitors, and combine the login form with pricing, special offers, and registration options on this custom page.
Further, since MemberPress rules protect only the post content outputted through the_content() function. In cases where some part of the content is being rendered outside of this function by some themes and plugins, that other content remains unprotected. In this case, setting up the Unauthorized Redirect is a great solution to protect your entire posts by redirecting users.
How To Set Up the Unauthorized Redirection
By default, on any protected post or page, unauthorized users will see the unauthorized message instead of the post content. If you enable the Unauthorized Redirect option, MemberPress will prevent unauthorized users from accessing the page and immediately redirect them to the page you specified.
To enable the unauthorized redirection, please follow these steps:
- Navigate to Dashboard > MemberPress > Settings > Pages tab, and scroll down to the "Unauthorized Access" section;
- Check the "Redirect unauthorized visitors to a specific URL" checkbox to enable the unauthorized redirection;
- Copy the URL or slug of your custom page to which you would like to redirect the unauthorized users, and add that to the "URL to direct unauthorized visitors to" field;
- Click the "Update Options" button to save changes.
NOTE: If the page used as your redirection URL is located on your site, you can use either the URL or only the slug. On the other hand, if you are redirecting users to the URL on some other site, you would need to use the whole URL.
Here, you will find some additional options:
- Redirect methods: by default, the template_redirect option will be selected here. If it happens that the MemberPress redirection doesn’t work with your WordPress theme, you can try changing it to the “init” option;
- Redirect non-singular views: enabling this option should hide protected posts in a non-singular view on the blog page, category pages, archive pages, etc.
NOTE: The page to which unauthorized users get redirected shouldn’t be protected by any MemberPress rules as this will create an indefinite loop and cause too many redirects error.
Please check the video tutorials below for more details on using the Unauthorized Redirect feature and step-by-step instructions.
Unauthorized Redirection Customizations
Next to default options available out of the box, you can do additional customizations of this feature using custom code snippets. The following unauthorized redirection customizations are available:
- Add Unauthorized Redirection Exclusions: Exclude specific posts or pages from unauthorized redirections based on their ID. Please check the dedicated article for more details on how to apply this customization;
- Add Rule-Specific Unauthorized Redirections: Set specific redirection URL for each rule based on rule ID. This way, if the rule is dedicated to a specific membership, you can use this code snippet to create membership-specific redirections. Please check the dedicated article for more details on how to apply this customization;
Create Custom Unauthorized Redirection Page
In addition, you can create the custom unauthorized redirection page and embed the MemberPress login form to it using the [mepr-login-form use_redirect="true"] shortcode. This option is especially useful if you want to have users redirected back to the protected post from which they got redirected after logging in. Please check the following article for more information on how to set that up: How to display login form and stay on the same protected post/page after login?
Is this not working how you think it should even after following the instructions in the video? Feel free to send us a Support Ticket!