“undefined” Appended to URL Causing 404 Page Not Found Error

Home»Cloud & Internet»Web Servers»“undefined” Appended to URL Causing 404 Page Not Found Error

When checking Apache HTTPD or Nginx web server access log, there are plenty of 404 Page Not Found in the access or error log caused by URLs that are been appended or added with /undefined at the end. For example:

https://example.com/undefined

And the Apache HTTPD web server log will have entry similar to below:

192.168.1.1 - - [DD/Mmm/YYYY:08:08:12 -0500] "GET /undefined HTTP/1.1" 404 27221 "https://techjourney.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36"

The 404 Page Not Found error may not visible on the front-end though, as redirection to the URL added with /undefined at the end may not actually occurred. Which means the visitor to the web page continues to be able to view the web page properly, but while loading the web page, a call to URL affixed with /undefined triggered 404 Page Not Found at the web server. However, in some cases, the redirection does occur and the visitors will be shown the 404 page.

In addition, the referer to the undefined request is also the actual page itself from the same IP address which has previously requested the actual page (correct URL without /undefined). This means that something on the actual page is triggering the request to undefined-appended URL.

There can be many reasons that can cause the /undefined appended to the end of URL without reason. Sometimes, it’s just not the fault of webmasters.

Reason and Resolution 1: Chrome Complityly Extension/Plugin

If the URL appended with “undefined” suffix happens exclusively on Google Chrome web browser, it may be caused by poorly written extensions or plugins. The main culprits are Complitly, a malware which may redirect your traffic to searchcompletion.com or other sites. Complitly injects an improved autocomplete feature that is calling “undefined” requests at every web pages that has a input text field with NAME or ID of “search”, “q” and more.

To prevent Complitly from messing with your web pages, do one of the following:

  • If it’s your Chrome web browser that is installed with Complitly, remove the Complitly extension immediately.
  • Change the NAME or ID of the input text field (such as search box) to uncommon name, such as hcraes and etc.
  • Add the following code to the header (within <head> and </head>) of the web pages:

    Note
    Complitly checks for a global variable nammed “suggestmeyes_loaded” to see if it’s already loaded. If the variable is set to true, it won’t load itself anymore, hence disable the plugin and stop it from requesting URLs with undefined appended.

Reason and Resolution 2: JavaScript

A lot of JavaScript on the web pages can construct URLs that are automatically resolved by the browser (for example, setting the src attribute on an image tag and setting a css-image attribute), and if there is bug in programming code, the undefined could be added to URLs unknowingly. JavaScript may be the main culprit is there is no visitors to your site haven’t complained about being redirected to 404 Page Not Found page or seeing any error page.

If JavaScript is the potential cause for the “undefined” 404 error, then you will need to spend a lot of time to debug and troubleshoot the code with various tools such as web console to find the root cause, especially when you’re relying on third-party plugins or JavaScript libraries.

However, there are common scenarios where JavaScript to add the /undefined to the end of the URL and trigger the call request to web server. For example, bug in coding causes data attribute to get lost and subsequent AJAX call is undefined, or JavaScript logic does not correctly handles all the possible outcomes when some variables are not formatted as expected, causing the logic to return undefined result, or the undefined error can happen if the logic encounters exception if JavaScript is used to set or change image locations, and many more. Sometimes, the undefined makes its way into the URI.

If you’re using WordPress, one plugin that can cause undefined URI issue is Elegant Theme’s Monarch plugin. The custom.js of Monarch plugin scans the images but on some images that are not formatted as expected, its this_img variable value turns to undefined, which subsequently leads to /undefined appending to the link address. To fix the issue, amend the following code at line 685 of custom.js:

Before:

if ( '' != this_img ) {

After:

if ( '' != this_img && typeof(this_img) !== 'undefined' ) {

Resolution 3: Redirect /undefined URL Back to Original Link Address

If you can’t figure out what’s causing the “undefined” URL issue, the last resort is to do a 301 permanent redirect the incorrect URL with “undefined” at the end back to orignal URL, effectively truncating the “undefined”.

Depending on your preference, there are multiple way to perform the redirection. For example, for .htaccess, add the following lines of code:

RewriteEngine On
RewriteRule ^(.*)/undefined?$ /$1 [L,NC,R=301]

You can also use PHP or even Apache or Nginx web server to perform the redirection. With redirection, the 404 Page Not Found error will be eliminated.

About the Author:

LK is a technology writer for Tech Journey with background of system and network administrator. He has be documenting his experiences in digital and technology world for over 15 years.Connect with LK through Tech Journey on Facebook, Twitter or Google+.

Pin It on Pinterest

Share This

Share This

Share this post with your friends!