I have a D7 site in a subfolder, and would like for AJAX requests to find the correct docroot folder.

When trying to login from localhost/mysite/user, AJAX sends a request to localhost/system/ajax. I've read that you can use the global variable $base_path for this, so I gave it a try, still the same error. I've checked in Firebug and indeed Drupal.settings.basePath does have the correct path. In settings.php is it written like this $base_path = '/mysite/';.

This made me wonder if the JS logic does not include the $base_path value by default and what would be a correct way to add this in. The site is tracked in Git, so I've also experimented with Apache configurations, such as ProxyPass, ProxyPassReverse, and ReWrite rules in order to prevent having to push changes that would risk breaking the site on the remote server.

I'm new to Drupal and not so experienced with Apache directives, any help here would be awesome :)

2 Answers 2


Took suggestion from Artur, problem solved by defining two domains in hosts file. One for the development environment and the other as a backup of the production environment. Then it was a case of setting up virtual hosts like this in httpd.conf (example for the development environment):

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName www.project.devel
    ServerAlias project.devel *.project.devel
    DocumentRoot /www/mysite/devel/docroot/
    RewriteEngine On
    RewriteOptions inherit

Login also worked even when domain was removed from the English language row in the languages table in the Drupal database. $base_url and $base_path also were commented out in settings.php, not needed with fake domains.


First off, in the settings.php file you should have an example of http://www.example.com and a comment there, saying that you should not append a trailing slash. Next, in your case looks like http://localhost would be the correct value of $base_url, if any - try hashing out $base_url line to see if the site is fine without it - as it might be.

  • Hi, I'm confused, is it the same problem that's referred above? To state is very shortly: $base_path is not included in AJAX requests when a form, such as a login form is submitted. Commented May 5, 2013 at 19:10
  • Assuming mysite is at the root of htdocs, you could try $base_url = 'http://localhost/mysite'; I prefer to establish a fake domain such as mysite.localhost.com - (codingcereal.com/2011/05/…). Then, I'm usually fine with base_url commented out. Just give it a try - the AJAX requests should point to correct location. Commented May 5, 2013 at 19:43
  • $base_url is set to http://localhost/mysite and $base_path is set to /mysite/ assuming $base_url and $base_path are not the same thing, correct? Or is the formatting wrong? Should a path start with the disk-mount's root folder? See reference. Because Drupal.settings.basePath is available, I assume that I must supply the global $base_path a value as well. Commented May 5, 2013 at 20:57
  • I will have a look into the suggestion you mentioned, I thought there would be some way that Drupal would add a base when the relevant variables are added to settings.php or if there is a Drupal way of injecting the base information somewhere in the codebase. Commented May 5, 2013 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.