A Jekyll plugin that generates server-specific redirection files (e.g., .htaccess
or firebase.json
) to improve SEO by allowing you to create server-side redirects with appropriate HTTP status codes.
- Server Support: Generate redirect configuration for:
- Firebase Hosting (
firebase.json
) - Apache (
.htaccess
)
- Firebase Hosting (
- SEO Optimization: Properly inform search engines about page moves using HTTP status codes.
- Jekyll Integration: Define redirects directly in your Jekyll pages and posts using
redirect_from
in the frontmatter.
-
Add the gem to your
Gemfile
:gem 'jekyll-server-side-redirects'
-
Run
bundle install
to install the gem.
If you're not using Bundler, you can install the gem manually:
gem install jekyll-server-side-redirects
Then, add it to your _config.yml file:
plugins:
- jekyll-server-side-redirects
Add the following configuration to your _config.yml file:
server_redirects:
server: 'apache' # Options: 'firebase', 'apache'
Define redirects in the redirect_from frontmatter field for your pages or posts:
---
title: "My New Page"
redirect_from:
- /old-page1/
- /another-old-page/
redirect_type: 302 # Optional: Defaults to 301 (permanent redirect)
---
When you build your site, the plugin will automatically generate the appropriate redirection file based on the configured server:
For Firebase, a firebase.json file will be created or updated. For Apache, a .htaccess file will be created or updated.
A firebase.json file will be generated as follows:
{
"hosting": {
"redirects": [
{ "source": "/old-page1/", "destination": "/new-page1/", "type": 301 },
{ "source": "/old-page2/", "destination": "/new-page2/", "type": 302 }
]
}
}
A .htaccess file will be generated as follows:
# .htaccess file generated by Jekyll Server-Side Redirects
Redirect 301 /old-page1/ /new-page1/
Redirect 302 /old-page2/ /new-page2/