Giter Site home page Giter Site logo

gareth-poole / gatsby-plugin-htaccess-redirects Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gatsbycentral/gatsby-plugin-htaccess-redirects

0.0 0.0 0.0 23 KB

Gatsby plugin to render redirects into a .htaccess file at public/.htaccess

License: MIT License

JavaScript 100.00%

gatsby-plugin-htaccess-redirects's Introduction

htaccess Redirects in Gatsby

If you want to host your Gatsby output with Apache, you can use a .htaccess file to have redirects processed server side. This plugin builds that file for you.

Options

The plugin accepts a prefix and suffix option which get prepended and appended to the built .htaccess file respectively.

Here's an example:

{
  resolve: `gatsby-plugin-htaccess-redirects`,
  options: {
    prefix: "<IfModule mod_rewrite.c>\nRewriteEngine On",
    suffix: "</IfModule>",
  },
},

NOTE: It's recommended to create an empty .htaccess file in static/. This plugin will append to an existing .htaccess file.

Advanced Options

By default the plugin will build one line per redirect like this:

RewriteRule ^from-path/?$ /to-path/ [R=301,L]

In apache2 this should cause a redirect from either /from-path or /from-path/ to /to-path/. This is built from the pattern RewriteRule ^%1/?$ %2 [R=%3,L]. This pattern receives the following replacements:

  • %1 -> fromPath (with the leading and trailing slashes removed)
  • %2 -> toPath (guaranteed to have a leading and trailing slash)
  • %3 -> Either 302 or 301 if isPermanent is false or true respectively

The option is called pattern and can be set like prefix and suffix.

Notes

It's currently untested (although expected to work) with a pathPrefix. Please let us know in an issue if you test this and it works (or doesn't).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.