Is it possible to enable a certain custom module under specific path only e.g. /store, and not load under other sections of a website? I am using Drupal 7.

  • 1
    No. When modules are enabled they are enabled. Depending on the module in question, and your goals, you may be able to configure it to do what you want, or override it with another module. But you cannot limit the module being enabled to fixed paths.
    – Jaypan
    May 9, 2019 at 22:21
  • I suspect you are asking the wrong question: would you care to describe what your objective is -- what is the reason you are asking about /store?
    – rivimey
    May 11, 2019 at 16:10

2 Answers 2


Well yes you can ... but you shouldn't you may want to think of the code quality of the custom module, because it should only be responsible for the exact functionality you require.

I say you can because yes:

$modules = ['custom_scarry_module'];
module_enable($modules, TRUE);

// Disable.
if (module_exists('custom_scarry_module')) {

But again perhaps rethink the "why" aka what Jaypan said.

  • module_enable() enables the module, as long as it is in one of the directories where Drupal looks for modules. You cannot tell Drupal "Install modules only from this directory."
    – apaderno
    May 10, 2019 at 13:21

Drupal looks for modules in the following directories inside the Drupal root directory. (The directories are listed in the order they are used when looking for modules.)

  • modules
  • profiles/$profile/modules
  • sites/all/modules
  • $conf/modules

$profile is the name of the profile used for the installation; $conf is the directory containing the settings.php file used for the site, which normally is sites/default.

Outside of those directories, and their sub-directories, Drupal doesn't look for modules.

Editing the sites.php file, you could tell Drupal the settings.php file to use is /store/settings.php. In that case, Drupal would look for modules in /store/modules, but also in the other directories I listed, including the modules directory, where Drupal core modules are.

To answer the question: No, it's not possible to make Drupal install and enable modules that are only in a specific directory and not other directories.

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.