Redirect 404 allows you to specify any number of servers that should be attempted to be redirected to if a 404 (Page not found) error is encountered. If a user encounters a 404 error, the module iterates through each of the specified servers and if the result is valid (2xx or 3xx status codes), they are redirected to that server while preserving the request URI. If none of the specified servers return valid results, the module can redirect to a search result page (if specified), a static URL page (with no request URI appended), the original/default 404 page within the site (variable site_404), or finally, if none of the attempts above can be used, the body and title of the 404 page may be specified.

Project page link: http://drupal.org/sandbox/vlad.pavlovic/1947784
git repository: git clone http://git.drupal.org/sandbox/vlad.pavlovic/1947784.git redirects_404

Drupal 7 only.

Reviews of other projects
http://drupal.org/node/1948406#comment-7208908
http://drupal.org/node/1946602#comment-7209264
http://drupal.org/node/1948100#comment-7209464
http://drupal.org/node/1936848#comment-7228202
http://drupal.org/node/1956202#comment-7242094
http://drupal.org/node/1957004#comment-7242206

Comments

PA robot’s picture

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

vlad.pavlovic’s picture

Issue summary: View changes

Added a review

vlad.pavlovic’s picture

Issue summary: View changes

Another review added.

vlad.pavlovic’s picture

Issue tags: +PAreview: review bonus
he0x410’s picture

Hello Vlad!

I like your module and would like introduce it to my team.

Automated review by http://ventral.org/: no errors/warnings :)

Manual review:

redirects_404.module
  • 94 | 'title' => variable_get('redirects_404_title', '404 - Page not found'), - not the best way to alter page title, because when you change redirects_404_title variable it doesn't clear cache, so page title still will be old and makes user confused. I suggest you to use hook_menu_alter and clear menu cache.
  • 152 | unused variable $data - you don't use curl return, so you can use less php memory, also above you set CURLOPT_RETURNTRANSFER = 1 to curl, maybe it will be faster to set 0, so you will decrease traffic
  • 197 | exit; - it's nicer to use drupal_exit, just a suggestion.

Good luck!

klausi’s picture

Status: Needs review » Needs work
Issue tags: -PAreview: review bonus

Manual review:

  1. redirects_404(): why do you need cURL and cannot use drupal_http_request()? And you should also implement hook_requirements() like http://api.drupal.org/api/drupal/modules!simpletest!simpletest.install/f...
  2. redirects_404_admin(): doc block is wrong, hook_admin() does not exist. See http://drupal.org/node/1354#forms
  3. "'access arguments' => array('administer redirects 404'),": that permission is not defined with hook_permission()?
  4. redirects_404(): why do you use check_url() here, you are not printing the $path to HTML anywhere? Make sure to read http://drupal.org/node/28984 again.
  5. Since the redirects_404_text variable can contain arbitrary user provided text you should either sanitize it before you return it in redirects_404() or mark the admin permission as 'restrict access' => TRUE in hook_permission().
  6. redirects_404_enable(): you set the site_404 to redirect404, but in hook_menu() you specify redirect_404, so does that even work?

Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

vlad.pavlovic’s picture

Status: Needs work » Needs review

First and formost, thank you both for taking the time to do the review. I am sorry about the somewhat delayed response, I've been sick the last few days.

I will attempt to answer each issue raised in order that they appear for clarity.

From artem.taranyuk:

1) I have changed the title generation to a title callback function. It just seemed a bit cleaner than to use hook_menu_alter and flush the menu cache. Hope that's ok.
2) CURLOPT_RETURNTRANSFER only determines what to do with curl_exec(). If set to TRUE, curl_exec doesn't output the result of the execution it returns it as a variable, which is what we want. I think that the setting you are refering to is CURLOPT_NOBODY, which uses HEAD and doesn't return any data. This is now moot though, since I switched to using drupal_http_request().
3) Done, changed to drupal_exit(), thanks!

From klausi:

1) The reason I had used cURL was because it is generally faster than stream_socket_clients, specifically when dealing with HEAD requests and because it natively recycles connections. It was a toss-up from day 1, really, some hosts have cURL and forbid stream_socket_clients connections, and others are the opposite way. In the future, if there is interest, I may make the module work with both methods. For the sake of this version and review, I have switched to using drupal_http_request(), as suggested.
2) WOW, my mistake, sorry. Fixed.
3) forgot to push the addition, sorry. Fixed.
4) Removed check_url, you are right, it doesn't belong.
5) Did both (sort of). I sanitized on validation and set the 'restrict access' to TRUE in hook_permissions.
6) Fixed.

Thank you both again for your reviews and subsequent suggestions, they are appreciated.

vlad.pavlovic’s picture

Issue summary: View changes

Another review.

vlad.pavlovic’s picture

Issue summary: View changes

Another review.

vlad.pavlovic’s picture

Issue summary: View changes

Review of Taxonomy menu block project application.

vlad.pavlovic’s picture

Issue tags: +PAreview: review bonus

Adding PAReview bonus.

SamChez’s picture

After doing some fiddling around with the configuration it looks quite reliable. The only issue I had, and I'm not even sure if it was the fault of the code, was that the redirect speed was lengthy. It got to where I redirected it but took quite a while to get there.

pagolo’s picture

The module seems to be useful and working.
If I specify the path of a legacy server, it works but I get this message:

Notice: Undefined property: stdClass::$redirect_code in redirects_404() (linea 160 di /home/drupal/public_html/sites/all/modules/redirects_404/redirects_404.module).
Notice: Undefined property: stdClass::$redirect_url in redirects_404() (linea 161 di /home/drupal/public_html/sites/all/modules/redirects_404/redirects_404.module)

vlad.pavlovic’s picture

Thank you both for the reviews, I appreciate you taking the time to do them.

Samuel, the perceived delay may be caused by the 2 second timeout that I allow for a connection. In the future I might allow the timeout to be configurable. Also, it could be caused by a myriad of other factors, such as server response times and may be out of our hands.

Paolo, you are absolutely right. I have fixed this issue and the notice is now gone.

Thank you both again.

klausi’s picture

Assigned: Unassigned » chx
Status: Needs review » Reviewed & tested by the community
Issue tags: -PAreview: review bonus

manual review:

  1. redirects_404_settings_validate(): do not run check_markup() when saving stuff to the DB. "When handling data, the golden rule is to store exactly what the user typed. When a user edits a post they created earlier, the form should contain the same things as it did when they first submitted it. This means that conversions are performed when content is output, not when saved to the database." from http://drupal.org/node/28984
  2. redirects_404(): instead of setting the location header and the status yourself use drupal_goto() instead.
  3. redirects_404(): this is also the place wehere you should run your check_markup() (although the config page is now protected by a high level admin permission, so it would not be necessary).

But otherwise looks RTBC to me. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

Assigning to chx as he might have time to take a final look at this.

vlad.pavlovic’s picture

Thank you for the review Klaus, below are my answers to the issues you have raised:

1) I have removed check_markup() from the redirects_404_settings_validate().
2) I could not use drupal_goto() because $_GET['destination'] is set on 404, and drupal_goto() marks it as an internal path and tries to redirect back to the same page causing a redirect loop. I thought, originally, that setting $options['absolute'] to TRUE would have skipped that, but after looking at common.inc, it turns out that $_GET['destination'] takes precedence. I understand and appreciate why it is that way. I hope it's ok.
3) I simply took out check_markup(). Since we do require high level admin permission, the user modifying the settings page should be trusted.

Thank you again for your review and the RTBC update, you're awesome.

chx’s picture

This shouldn't affect RTBC.

  1. There's no need, not even for readability to use ($is_https) , just $is_https is fine.
  2. $header_info = drupal_http_request($path, array('method' => 'HEAD', 'timeout' => 2)); that timeout won't help you. The module will be rife with support requests from people who find it doesn't work. We learned the hard that drupal_http_request does not work in many environment and times out really unreliably. I wonder whether a client side solution would be better. For what this does, it's fine, I am just warning you.
vlad.pavlovic’s picture

Thank you for taking the time to look it over Charlie, I appreciate it.

1. You are absolutely right, old habits die hard.
2. I think that the first version I release will include a choice between using cURL (if available) and drupal_http_request. I have not thought about a client-side redirect, but that might become a good choice for people struggling with the other 2, though I have rarely had problems with cURL.

Thank you very much!

chx’s picture

It does not matter whether you use drupal_http_request or cURL alas, this is about retarded shared host firewall settings.

vlad.pavlovic’s picture

I see what you mean. You were talking about firewalls blocking all outbound connections, not that the returning/incoming connection would be an issue, per se.

chx’s picture

Exactly.

vlad.pavlovic’s picture

Thank you again, hope I am not wasting too much of your time.

A client-side/jquery type solution would work, and I will surely add it. I just worry that I will then run into same origin policy issues if I use jQuery.ajax() to check if the path is valid before I redirect.

klausi’s picture

Status: Reviewed & tested by the community » Fixed

no other objections for more than a week, so ...

Thanks for your contribution, vlad.pavlovic!

I updated your account to let you promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and get involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

vlad.pavlovic’s picture

Thank you all for taking the time to review the project.

It is now located at: http://drupal.org/project/redirect_404 (I took out the 's' from redirects).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Another review.