Skip to content

Assemble an .htaccess file from a base file and an arbitrary number of modules.

License

Notifications You must be signed in to change notification settings

gebruederheitz/htmodules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

1464d1f · Jul 10, 2024

History

6 Commits
Oct 25, 2021
Oct 25, 2021
Oct 25, 2021
Oct 25, 2021
Oct 25, 2021
Oct 25, 2021
Oct 25, 2021
Oct 25, 2021
Oct 25, 2021
Oct 25, 2021
Jul 10, 2024
Oct 25, 2021
Oct 25, 2021
Oct 25, 2021
Oct 25, 2021
Jul 10, 2024
Jul 10, 2024

Repository files navigation

htmodules

Assemble an .htaccess file from a base file and an arbitrary number of modules


This library will parse a base .htaccess file and attempt to find "blocks" surrounded by # BEGIN ${blockName} and # END ${blockName} comments. These blocks can be replaced or appended via separate files ("module files"). These must be in the same directory as the base file and follow the naming format %blockName%.htaccess (replacing %blockName% with the module name / block name that corresponds to the blockName in the comments).

An example of how the files are combined as well as a list of caveats can be found in the documentation of the underlying @gebruederheitz/plaintextlego package.

Installation

npm install @gebruederheitz/htmodules

CLI Usage

# Will try to find the nearest .htaccess from the current directory upwards
$> npx htmodules

# Passing a custom base file that will be modified
$> npx htmodules ./apache-dir.conf

# or

$> ./node_modules/bin/htmodules

You can use this from the node scripts in your package.json:

{
  "scripts": {
    "build:htaccess": "htmodules",
    "build:apacheconf": "htmodules /var/www/mysite/public/apache-dir.conf"
  }
}

Code Usage

// ES module import
import { HtModules } from '@gebruederheitz/htmodules';
// or, for CJS use (e.g. older node)
const { HtModules } = require('@gebruederheitz/htmodules');

// Automatically find the nearest .htaccess upwards and modules in the same
// directory and apply the modules to the base file
new HtModules();

// or provide a specific base file to work on
new HtModules(path.resolve('./apache-dir.conf'));

About

Assemble an .htaccess file from a base file and an arbitrary number of modules.

Resources

License

Stars

Watchers

Forks

Releases

No releases published