Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

[Solved] 404 Page Not Found Errors - AJAX Only

j2234j2234
edited July 2014 in Vanilla 2.0 - 2.8

I'm suddenly getting 404 Not Found errors for certain AJAX requests. An example screenshot from the registration page is attached.

It is saying that it's getting a 404 for this URL, but when I load it in the browser, it shows TRUE:
/forum/dashboard/user/usernameavailable/asdf

I read this tutorial and my .htaccess file seems to be fine. I've posted a copy of it here.

I'm also getting errors for similar AJAX requests like: "The requested URL /profile/notificationspopin was not found on this server." The URL does exist when loaded in the browser.

Version number: 2.1
PHP Version 5.3.28

If you want to reproduce the bug, you can fill out the registration form and the errors will show before you submit the form.

Thanks in advance...

«1

Comments

  • Options
    j2234j2234
    edited July 2014

    Here's a little more info:

    The error messages look like this:
    The requested URL /dashboard/user/emailavailable was not found on this server.

    But in the browser console, the requested URL is:
    codeselfstudy.com/dashboard/user/emailavailable?email=asdf

    It should be codeselfstudy.com/forum/dashboard/user/emailavailable?email=asdf.

    How do I tell the forum to include the "forum/" in the URL? It isn't that the page doesn't exist -- the forum is requesting the wrong URL.

    Edit: I've also deleted all the .ini files in the cache folders.

  • Options

    I think I found the bug.
    applications/dashboard/js/entry.js?v=2.1

    The code says:
    var checkUrl = gdn.url('/dashboard/user/emailavailable');

    which won't work on forums that are in subdirectories, because it's requesting dashboard with a leading slash.

    I'll double-check it and then submit a bug report, if that's what the problem is.

  • Options
    peregrineperegrine MVP
    edited July 2014

    your checkUrl is evaluating to

    /dashboard/user/emailavailable

    if its not rewriting urls it should be prefixing with

    /forum/index.php?p=

    it should look like this. checkUrl should evaluate to

    /forum/index.php?p=/dashboard/user/emailavailable

    you might try in conf/config.php so your urls are rewritten.

    $Configuration['Garden']['RewriteUrls'] = TRUE;
    

    then checkUrl should evaluate to:

    /forum/dashboard/user/emailavailable

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    Thanks for the reply. I have RewriteUrls set to TRUE. Here's that section of the config file:

    $Configuration['Garden']['InputFormatter'] = 'Html';
    $Configuration['Garden']['Version'] = '2.1';
    $Configuration['Garden']['RewriteUrls'] = TRUE;
    $Configuration['Garden']['Cdns']['Disable'] = FALSE;
    $Configuration['Garden']['CanProcessImages'] = TRUE;
    $Configuration['Garden']['SystemUserID'] = '2';
    $Configuration['Garden']['Installed'] = TRUE;

    The rewriting of URLs works, but it appears to be requesting the wrong URL in the JavaScript.

    The JavaScript says:
    var checkUrl = gdn.url('/dashboard/user/emailavailable');

    but there is no Vanilla installation at / -- just at /forum. I'll check what the gdn.url method does in the meantime.

  • Options
    peregrineperegrine MVP
    edited July 2014

    but its not rewriting otherwise you wouldn't see this

    http://codeselfstudy.com/forum/entry/register?Target=discussions

    is your .htaccess being read? and is it located in the /forum folder.

    and is modrewrite working.

    you could also try

    $Configuration['Garden']['RewriteUrls'] = FALSE;

    and see if that works.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    peregrineperegrine MVP
    edited July 2014

    In order to use mod_rewrite you can type the following command in the terminal:

    a2enmod rewrite

    restart apache.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    check your php loaded modules

    for

    mod_rewrite

    you can use php_info

    or you can download the
    http://vanillaforums.org/addon/versioncheck-plugin

    which has it included for easy viewing from the dashboard.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    peregrineperegrine MVP
    edited July 2014

    as you can see rewritng is not taking place when you click register other wise it wouldn't be going to the url in the first image.

    and your checkUrl is not prefixing the /forum/index.php?p=

    as it should if rewriting is not taking place. (perhaps because you don't have modrewrite enabled, yet you specify in config that you will be rewriting).

    the leading / , that you are chasing is a red herring I believe.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    I'm a bit confused. I think the rewriting is working, because URLs like this work:
    http://codeselfstudy.com/forum/discussion/6/welcome-to-the-site

    If rewrites weren't working, wouldn't there would be an index.php?p=/path/to/the/page in the URL?

    I think it still uses query strings for redirects even when rewriting is on. Even on this vanillaforums.org site, registration URLs have query strings for the redirect:
    /entry/register?Target=discussion%2Fcomment%2F212500

    Unfortunately, it's a managed server, but I'm sure that .htaccess works for rewriting in general, since I have a lot of sites on the server. This is from their FAQs:
    http://qa.site5.com/advanced/does-site5-have-mod_rewrite-enabled/

  • Options
    j2234j2234
    edited July 2014

    It does work now for the moment, because I just hardcoded /forum in the JavaScript file. But I'm not sure if that will cause problems down the road.

  • Options
    peregrineperegrine MVP
    edited July 2014

    you can obviously verify with phpinfo to see if module is loaded.

    you could be correct. it just seems odd.

    I think something is wrong with UrlFormat in your setup for whatever reason.

    var urlFormat = gdn.definition("UrlFormat", "/{Path}");

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    j2234j2234
    edited July 2014

    phpinfo() isn't showing mod_rewrite or anything that begins with mod_, but I think it's enabled -- otherwise the rewriting wouldn't work on the discussion URLs. I've sent a support ticket just to be sure though.

    You don't think it's a problem with the client side? The JavaScript is omitting the "forum" directory from the URL on AJAX requests. So it requests this:
    codeselfstudy.com/dashboard/user/emailavailable?email=fdsa

    rather than this:
    codeselfstudy.com/forum/dashboard/user/emailavailable?email=fdsa

    Is there something in the PHP that would tell the gdn.url() method to use "forum"? I'm still looking through the JS...

    Thanks for your help, by the way. :smile:

  • Options

    I haven't heard back from the hosting company yet, but this .htaccess rewrite rule works, for example:
    http://codeselfstudy.com/forums/structure-and-interpretation-computer-programs-first-meeting-24.html
    (watch the redirect from that to a Vanilla-style URL)

    If I delete the .htaccess file and turn off rewriting in the config file, I get URLs like this and the 404 AJAX errors still appear:
    codeselfstudy.com/forum/index.php?p=/entry/register&Target=discussion%2F6%2Fwelcome-to-the-site

    Does anyone know if there are settings in the database that might affect this, or could I just re-upload all the Vanilla files and hope it overwrites whatever might have gone wrong?

  • Options
    peregrineperegrine MVP
    edited July 2014

    just for grins can you post your entire config.php

    but leave out sensitive info like passwords, salts, keys and email stuff.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    Sure, I'll post it in a minute.

    The hosting company said that mod_rewrite is enabled, but that it won't show in phpinfo(). This is their reply:

    Mod_rewrite is an apache module and not a PHP function. You can review our list of Apache modules here: http://kb.site5.com/apache/loaded-apache-modules/

    You would be able to enable the mod_rewrite option via your .htaccess file by adding this code:

    RewriteEngine On

    Then the necessary code for your rewrite(s) to function as needed following that line.

  • Options

    you might want to console log value of the variable urlFormat

    here

    https://github.com/vanilla/vanilla/blob/2.1/js/global.js#L637

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    @peregrine said:
    you might want to console log value of the variable urlFormat

    Good idea. I just tried that and it isn't creating the correct URL.

    Screenshot of the console:

  • Options
    peregrineperegrine MVP
    edited July 2014

    nothing pops out at me.

    you might want to console log value of the variable urlFormat

    here is what I changed to adding console.logging.

    https://github.com/vanilla/vanilla/blob/2.1/js/global.js#L637

         gdn.url = function(path) {
               console.log("path is " + path);
              if (path.indexOf("//") >= 0)
                 return path; // this is an absolute path.
    
              var urlFormat = gdn.definition("UrlFormat", "/{Path}");
              console.log("format is:" + urlFormat);
    
              if (path.substr(0, 1) == "/")
                 path = path.substr(1);
    
              if (urlFormat.indexOf("?") >= 0)
                 path = path.replace("?", "&");
    
              return urlFormat.replace("{Path}", path);
           };
    

    then look at your console log

    e.g. mine shows when I try to register testuser. my folder is /vanilla

    path is /dashboard/user/usernameavailable/testuser
    global.js?v=2.1 (line 636)
    format is:/vanilla/{Path}
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    peregrineperegrine MVP
    edited July 2014

    your urlFormat seems to evaluate to

    /{Path}

    the differences could be I'm testing on local host. but logging should give you some ideas.

    not sure but possibly config statement with webroot might help. not sure.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.