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.
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).
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 http://localhost/mysite/devel/docroot/user
because the AJAX request would go to http://localhost/system/ajax
or http://localhost/ajax_register/login/ajax
and therefore would not return the correct JSON response.
How can this be solved? Are configurations in Apache's httpd.conf
or .htaccess
enough to make this work?
Here's what I did so far, first in settings.php
:
$base_url = 'http://localhost/mysite/devel/docroot';
$base_path = '/mysite/devel/docroot/';
Next, I've tried the following with rewrite rules in httpd.conf
:
<IfModule mod_rewrite.c>
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
</IfModule>
Here I got the following pop up with HTML (that seems to be from index.php
) in the response text instead of the expected JSON response:
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...
Then without rewrite rules but using proxies instead in httpd.conf
:
<IfModule mod_proxy.c>
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
RewriteEngine on
ProxyPass /system/ http://localhost/mysite/devel/docroot/system/
ProxyPassReverse /system/ http://localhost/mysite/devel/docroot/system/
<Location /system/>
Order allow,deny
Allow from all
</Location>
ProxyPass /ajax_register/ http://localhost/mysite/devel/docroot/ajax_register/
ProxyPassReverse /ajax_register/ http://localhost/mysite/devel/docroot/ajax_register/
<Location /ajax_register/>
Order allow,deny
Allow from all
</Location>
</IfModule>
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.
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...
Without both the rewrite rules and the proxy directives I get the following error in the JavaScript pop up:
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.
Finally in .htaccess
I've tried to rewrite the base to the following:
RewriteBase /mysite/devel/docroot/
and here I get the same 404 error as was the case when both the rewrite rules and proxy directives are commented out in httpd.conf
. I would also like to add that in the database, in the table languages
I've set the domain for the English language to localhost
.
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 Drupal.settings.basePath
in Firebug I do get the value that I've set in settings.php
:S - Does someone have any ideas?