Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX URL requests in Drupal 7 on localhost Apache2 don't include base URL or base path
    primarykey
    data
    text
    <p>I am currently stuck with a problem in my local Drupal 7 environment. As Drupal 7 site configurations can get very complex, I will try to explain my problem in as much details as possible.</p> <p>The site sits in a sub folder in my local environment, I have more projects running on my localhost, so preferably I would like to keep the projects separated. In addition, for this site I have two separate folders, one for development and one for production that share the same database, so a solution by adding fake domains would not work here I think (correct me if I'm wrong).</p> <p>So the main problem seems to be that AJAX requests don't include the base URL or base path and I can't login on <code>http://localhost/mysite/devel/docroot/user</code> because the AJAX request would go to <code>http://localhost/system/ajax</code> or <code>http://localhost/ajax_register/login/ajax</code> and therefore would not return the correct JSON response.</p> <p>How can this be solved? Are configurations in Apache's <code>httpd.conf</code> or <code>.htaccess</code> enough to make this work?</p> <p>Here's what I did so far, first in <code>settings.php</code>:</p> <pre><code>$base_url = 'http://localhost/mysite/devel/docroot'; $base_path = '/mysite/devel/docroot/'; </code></pre> <p>Next, I've tried the following with rewrite rules in <code>httpd.conf</code>:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine on RewriteCond %{HTTP_REFERER} .*devel.*$ [OR] RewriteRule ^/sites/(.*)$ /mysite/devel/docroot/sites/$1 RewriteRule ^/system/(.*)$ /mysite/devel/docroot/system/$1 RewriteRule ^/ajax_register/(.*)$ /mysite/devel/docroot/ajax_register/$1 &lt;/IfModule&gt; </code></pre> <p>Here I got the following pop up with HTML (that seems to be from <code>index.php</code>) in the response text instead of the expected JSON response:</p> <pre><code>An AJAX HTTP error occurred. HTTP Result Code: 404 Debugging information follows. Path: http://localhost/ajax_register/login/ajax StatusText: error ResponseText: lots of HTML... </code></pre> <p>Then without rewrite rules but using proxies instead in <code>httpd.conf</code>:</p> <pre><code>&lt;IfModule mod_proxy.c&gt; ProxyRequests Off ProxyPreserveHost On &lt;Proxy *&gt; Order deny,allow Allow from all &lt;/Proxy&gt; RewriteEngine on ProxyPass /system/ http://localhost/mysite/devel/docroot/system/ ProxyPassReverse /system/ http://localhost/mysite/devel/docroot/system/ &lt;Location /system/&gt; Order allow,deny Allow from all &lt;/Location&gt; ProxyPass /ajax_register/ http://localhost/mysite/devel/docroot/ajax_register/ ProxyPassReverse /ajax_register/ http://localhost/mysite/devel/docroot/ajax_register/ &lt;Location /ajax_register/&gt; Order allow,deny Allow from all &lt;/Location&gt; &lt;/IfModule&gt; </code></pre> <p>For the proxy directives, a similar 404 not found error was given for the POST AJAX request, except that now the response text is in JSON format.</p> <pre><code>An AJAX HTTP error occurred. HTTP Result Code: 404 Debugging information follows. Path: http://localhost/ajax_register/login/ajax StatusText: error ResponseText: some JSON code... </code></pre> <p>Without both the rewrite rules and the proxy directives I get the following error in the JavaScript pop up:</p> <pre><code>An AJAX HTTP error occurred. HTTP Result Code: 404 Debugging information follows. Path: http://localhost/ajax_register/login/ajax StatusText: error ResponseText: 404 Not Found Not Found The requested URL /ajax_register/login/ajax was not found on this server. </code></pre> <p>Finally in <code>.htaccess</code> I've tried to rewrite the base to the following:</p> <pre><code>RewriteBase /mysite/devel/docroot/ </code></pre> <p>and here I get the same 404 error as was the case when both the rewrite rules and proxy directives are commented out in <code>httpd.conf</code>. I would also like to add that in the database, in the table <code>languages</code> I've set the domain for the English language to <code>localhost</code>.</p> <p>I don't understand, why is the base not included in front of the AJAX URL requests? And how can I add it? When I query <code>Drupal.settings.basePath</code> in Firebug I do get the value that I've set in <code>settings.php</code> :S - Does someone have any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload