
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
gridsome-plugin-htaccess
Advanced tools
Generates a .htaccess file at build time according to your options and save it at the root of your dist folder.
Generates a .htaccess file at build time according to your options and save it at the root of your dist folder.
I made this plugin because I am using Gridsome to build a static website that I host on an host provider that runs an Apache server.
I needed a reliable and flexible way to generate my .htaccess
without having to worry about typos or boilerplate syntaxes.
.htaccess
file at the root of your dist
file.htaccess-custom
at the start or the end of the generated .htaccess
when you cannot find enough flexibility with the available optionsGridsome installed (version 0.*).
With NPM:
npm install --save-dev gridsome-plugin-htaccess
With Yarn:
yarn add --dev gridsome-plugin-htaccess
In your file gridsome.config.js
, add the gridsome-plugin-htaccess
plugin in your plugins
.
module.exports = {
siteName: "Gridsome",
plugins: [
{
use: "gridsome-plugin-htaccess",
},
],
};
Add an example option (enabling GZIP compression for HTML files).
module.exports = {
siteName: "Gridsome",
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
textCompression: ["text/html"],
},
},
],
};
Build your project.
gridsome build
You should see something like this in your terminal.
$ gridsome build
Gridsome v0.7.12
Initializing plugins...
Load sources - 0s
Create GraphQL schema - 0.02s
Create pages and templates - 0.03s
Generate temporary code - 0.05s
Bootstrap finish - 0.95s
gridsome-plugin-htaccess: 0.613ms <---------
Compile assets - 4.34s
Execute GraphQL (3 queries) - 0s
Write out page data (3 files) - 0.01s
Render HTML (3 files) - 0.3s
Process files (0 files) - 0s
Process images (9 images) - 0.79s
Done in 6.49s
Now check on the .htaccess
file in your dist
folder. You should see this content.
# Enable text compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
</IfModule>
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
blockedIp: ["192.168.0.1", "8.8.4.4"],
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
blockedUserAgents: ["googlebot", "yandexbot", "bingbot"],
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
contentSecurityPolicy: {
"frame-src": ["self", "youtube.com"],
"script-src": ["self"],
"font-src": ["fonts.google.com"],
},
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
customcontent: {
order: "after",
content: "SSLProtocol -ALL +TLSv1.2",
},
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
customHeaders: {
"X-Powered-By": "Gridsome 0.7.12",
},
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
disableDirectoryIndex: true,
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
disableServerSignature: true,
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
featurePolicy: {
geolocation: ["none"],
battery: ["self"],
"ambient-light-sensor": ["self", "amazon.com"],
},
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
fileExpirations: {
fileTypes: {
"text/html": "access plus 1 day",
"image/png": "access plus 1 week",
},
},
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
fileExpirations: {
default: "access plus 1 month",
},
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
forceHttps: true,
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
notCachedFiles: ["/service-worker.js", "/assets/js/service-worker.js"],
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
pingable: false,
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
preventDdosAttacks: {
downloadedFilesSizeLimit: 102400, // in bytes
},
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
preventScriptInjection: true,
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
redirections: [
{
from: "/about",
to: "/about-us",
},
{
from: "/webp",
to: "https://dev.to/webp",
},
],
},
},
],
};
// gridsome.config.js
module.exports = {
plugins: [
{
use: "gridsome-plugin-htaccess",
options: {
textCompression: [
"text/html",
"application/javascript",
"text/css",
"image/png",
],
},
},
],
};
You will find the types of the complex types right below this list. Options specified with the "?:" means non mandatory keys.
Array<string>
A list of IP to block from being able to browser your web app. Order Apache documentation.Array<string>
A list of user agents you want to prevent from accessing your server files, to save your server resources for example.ContentSecurityPolicy
A set of key-value pairs that holds your content security policies. You do not need to single-quote the following values (this is done for you): none
, src
, self
, unsafe-eval
, unsafe-hashes
, unsafe-inline
, strict-dynamic
and report-sample
. Content-SecurityPolicy MDN documentation.CustomContent
Some custom content to append or prerend to the generated htaccess content.CustomHeaders
A set of key-value pairs to add custom headers to each responses. Headers Apache documentation.Boolean
If set to true, will add a rule to disable the directory index. Directory index Apache documentation.Boolean
If set to true, will add a rule to prevent sending the server signature in each responses. Server signature Apache documentation.FeaturePolicy
A set of key-value pairs holding your feature policies. Feature-Policy MDN documentation.FileExpirations
An object that let you control how your file types should be cached by the browser. You can also set a default file cache. ExpiresByType Apache documentation.Boolean
If set to true, will add a rule to force your users' browser to go to the HTTPS version of your web app.Array<string>
A list of file paths that you want to prevent from being cached by your users' browser.Boolean
If set to true, will add a rule to prevent to ping your domain.DdosAttackPreventionOption
An object you can specify to tell how many bytes maximum your browser should request.Boolean
If set to true, will add a rule to prevent scripts injections in the URL.Array<Redirection>
An array of objects to specify 301 redirections. Redirect Apache documentationArray<string>
An array of MIME types you want your server to compress before sending its content to the browser. Deflate Apache documentation.interface ContentSecurityPolicy {
[key: string]: Array<string>;
}
interface FeaturePolicy {
[key: string]: Array<string>;
}
interface Redirection {
from: string;
to: string;
}
interface DdosAttackPreventionOption {
downloadedFilesSizeLimit: number;
}
interface CustomContent {
order: "before" | "after";
content: string;
}
interface CustomHeaders {
[key: string]: string;
}
interface FileExpirations {
default?: string;
fileTypes?: FileType;
}
interface FileType {
[key: string]: string;
}
[0.2.1] 2020-01-25
.htaccess
file
disableServerSignature
(set to true
)fileExpirations
preventScriptInjection
(set to true
)notCachedFiles
FAQs
Generates a .htaccess file at build time according to your options and save it at the root of your dist folder.
The npm package gridsome-plugin-htaccess receives a total of 10 weekly downloads. As such, gridsome-plugin-htaccess popularity was classified as not popular.
We found that gridsome-plugin-htaccess demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.