2

In my client's site it is normal to delete some posts (or old posts), but I don't want a 404 error page. Instead I want the user/visitor to be redirected to the frontpage with a 301 error code.

I have installed the Redirect module, but I have not found any option for this.

I have the Rules module installed and I can create custom module rule if I need.

  • What is the question? Are you asking if the Redirect module is really not able to do what you are trying to achieve? Are you asking how to achieve it with the Rule module, or how to do it with a custom module? So far, you stated facts, without any explicit question. – kiamlaluno Jan 27 '16 at 10:53
1

I found the module Save Redirect on Delete which looks like it addresses your problem. From the description:

The Save Redirect On Delete module gives the functionality for saving redirects after deletion of entity(supported by pathauto module) having some url alias.

I haven't tried it myself but would be interested to know if it helps.

0

There must be a better way, but one way will be to create a page with script to redirect your page.

<script>
  alert("A message for visitor if you want to show");
  window.location.replace("http://your_site.whatever");
</script>

After creating the page with javascrip code, Go to admin/config/system/site-information and change the Default 404 (not found) page to point your page with javacript code.

  • Re "will be to create a page with script to redirect your page": No, it is not, since the OP is talking about deleting a node. You cannot create a page to redirect, since the page from which redirecting is the node deletion page, an existing one. – kiamlaluno Jan 27 '16 at 10:12
  • @kiamlaluno That shouldn't be a problem at all, from what i understand need to redirect all 404 to home page. my approach is simple but not the best i guess. If he create a page e.g redirect and add the javascript code to point homepage. then he can go to admin/config/system/site-information, update Default 404 (not found) page to link to redirect page. now all the 404 request will point to redirect page and javascript will take care of the rest. – Yama Jan 27 '16 at 10:19
  • Maybe I misunderstood the OP, who is not probably talking about redirecting users after they delete a node. He is talking about deleted nodes, and a 404 error page. I guess the OP means redirecting the users who visit the URL of a deleted node to the front page, with a 301 error code. You cannot do that in JavaScript. – kiamlaluno Jan 27 '16 at 10:34
0

If the question here can be translated to something like "How to redirect to frontpage when trying to visiting a node that has been deleted before?", then there are 2 options to do so, as detailed below.

Option 1: Use the Rules module

Assume the path of the "Default 404" page is set to not_found (via admin). And assume your homepage has a path like my_homepage.

Then create a rule using the Rules module, with as Event something like "After visiting node not_found". So that the entire rule would look something like so:

  • Rules Event: After visiting node not_found
  • Rules Action: Page redirect - Parameter: URL: my_homepage

Should you want to do so, you could also add another Rules Action to also display some (informational) message in the Drupal message area, with something like "You tried to visit a page which has been deleted, which is why we're showing you the homepage instead".

Option 2: Use the CustomError module

The CustomError module allows the site admin to create custom error pages for HTTP status codes 403 (access denied) and 404 (not found), without creating nodes for each of them. Some of its features are like so (from its project page):

  • Configurable page title and descriptions.
  • There are no author and date/time headers as with normal nodes.
  • Any HTML formatted text can be put in the page body.
  • The error pages are theme-able.
  • Users who are not logged in and try to access an area that requires login will be redirected to the page they were trying to access after they login.
  • Allows custom redirects for 404s.

Note the part about "Allows custom redirects for 404s.", which I believe is what you're looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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