htaccess-configs-mydevil

.htaccess boilerplate configs for MyDevil hosting

Usage no npm install needed!

<script type="module">
  import htaccessConfigsMydevil from 'https://cdn.skypack.dev/htaccess-configs-mydevil';
</script>

README

MyDevil .htaccess Configs

Build Status

MyDevil .htaccess Configs is a collection of configuration snippets that can help your server improve the web site's performance and security, while also ensuring that resources are served with the correct content-type and are accessible, if needed, even cross-domain.

This is a fork of the Apache Server Configs prepared for MyDevil hosting.

Getting Started

There are a few options for getting the MyDevil .htaccess configs:

  • Download the zip archive
  • Install them via npm: npm install --save-dev htaccess-configs-mydevil

Inside the dist/ folder, you'll find a ready-to-use .htaccess file.

Usage

Copy the .htaccess file in the root of the website.

Custom .htaccess builds

Security, mime-type, and caching best practices evolve, and so should do your .htaccess file. In the past, with each new MyDevil .htaccess Configs release it was quite tedious to find out which .htaccess trick was just new or only had changes in certain nuances.

The build script with its re-usable and customizable build configuration lets you easily update your .htaccess file. Each new .htaccess build will contain the updated MyDevil .htaccess Configs source files, enabled or commented-out according to your settings in the htaccess.conf of your project root.

Configuration file: htaccess.conf

Allows you to define which module to enable or disable for your project. Just copy the default htaccess.conf from this repo into your project directory. Adjust to your needs, and/or add custom code snippets you need for your project. Its syntax is straight and pretty much self-explanatory:

# Example Module

title   "example module"
enable  "src/example-module/images.conf"
enable  "src/example-module/web_fonts.conf"
disable "src/example-module/not-needed.conf"
omit    "src/example-module/not-needed-at-all.conf"

... more modules ...

Disabling modules

For example, the “Cross-origin web fonts” snippet is always included in our pre-built .htaccess file and enabled. If your project does not deal with web fonts, you can disable or omit this section:

This will comment out the section:

disable  "src/cross-origin/web_fonts.conf"

…and this will exclude the section, saving lines in output:

omit  "src/cross-origin/web_fonts.conf"

Enabling modules

For example, the “Forcing https://” snippet is disabled by default, although being included in our pre-built .htaccess. To enable this snippet, change the disable keyword to enable:

enable "src/rewrites/rewrite_http_to_https.conf"

Adding custom modules

Imagine you're passing all requests to non-existing files to your favourite web framework. The according mod_rewrite snippet would go like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

Store this snippet in a file, e.g. config/framework_rewrites.conf, and add a reference in your htaccess.conf:

# PROJECT MODULES
enable "config/framework_rewrites.conf"

Build script: build.sh

Dive into your project root and call the build script from wherever you cloned the repo. Here are three examples:

1. Create a default .htaccess
in current work directory. An existing htaccess.conf in this directory will be used; if none is present, the default configuration will apply.

$ path/to/htaccess-configs-mydevil/bin/build.sh

# Output looks like:
[✔] Build .htaccess
[✔] Moved in place: './.htaccess'

2. Custom output location
Just add output path and filename as parameter. By the way, if there's an existing .htaccess file, the build script will create a backup.

$ path/to/htaccess-configs-mydevil/bin/build.sh htdocs/.htaccess
[✔] Build .htaccess
[✔] Create backup: 'htdocs/.htaccess~'
[✔] Moved in place: 'htdocs/.htaccess'

3. Custom .htaccess configuration
Why not maintain your personal ~/htaccess.conf? This example creates a .htaccess in current work directory, according to your favourite settings you may have stored in your $HOME directory:

$ path/to/htaccess-configs-mydevil/bin/build.sh ./.htaccess ~/htaccess.conf

Support

  • MyDevil hosting

  • Apache v2.4.0+

  • Browsers:

    • Chrome
    • Firefox 4+
    • Internet Explorer 8+
    • Opera 12+
    • Safari 5+

Unsupported modules from original project

Custom error messages/pages

MyDevil does not support ErrorDocument. However, there is a workaround. You can create custom error pages in directory /errors/xxx.html when xxx is HTTP code.

Link to the official documentation (in polish): Własne strony błędów

Disable TRACE HTTP Method

Due to the lack of access to the main configuration, the option is not available.

Server-side technology information

MyDevil does not support Header unset. There is no workaround at the moment.

ServerTokens Prod

Due to the lack of access to the main configuration, the option is not available.

Compression

MyDevil does not support AddOutputFilterByType DEFLATE. However, there is a workaround. You can enable GZIP compression at your page settings.

Link to the official documentation (in polish): Strona WWW/PHP

Brotli/GZip pre-compressed content

Due to the lack of compression, the option is also not available.

ETags

MyDevil does not support Header unset. There is no workaround at the moment.

File concatenation

MyDevil does not support

Options +Includes
AddOutputFilterByType INCLUDES
SetOutputFilter INCLUDES

There is no workaround at the moment.

Contributing

Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the guidelines:

Acknowledgements

MyDevil .htaccess Configs is only possible thanks to all the awesome contributors!

Apache Server Configs is only possible thanks to all the awesome contributors!

License

The code is available under the MIT license.