Htaccess Redirect Generator API
Generate Apache .htaccess and Nginx redirect rules: single page, bulk list, domain move, force HTTPS, add or remove www, add or remove trailing slashes.
POST /api/v1/tools/htaccess-redirect-generatorMCP htaccess_redirect_generatorWeb & SEOGenerate 301 and 302 redirects for .htaccess and Nginx: single pages, bulk lists, domain moves, HTTP to HTTPS, www and trailing slashes, safely escaped.
Input
Send these as a JSON object. Unknown fields are rejected.
- mode
- page: one old path to one new URL (from, to). bulk: many pairs (pairs). domain: move oldDomain to newDomain. https: force HTTPS (domain optional). www-add / www-remove: canonical host (domain). slash-add / slash-remove: trailing slashes. (string, one of page, bulk, domain, https, www-add, www-remove, slash-add, slash-remove, default "page")
- code
- HTTP status: 301 (permanent) or 302 (temporary). (integer, 301 to 302, default 301)
- apacheStyle
- Apache module for page and bulk modes: rewrite (mod_rewrite) or alias (mod_alias Redirect lines). (string, one of rewrite, alias, default "rewrite")
- from
- page mode: the old path or URL, e.g. /old-page.html. (string, up to 2048 characters)
- to
- page mode: the new path or absolute URL. (string, up to 2048 characters)
- pairs
- bulk mode: one "old new" pair per line, separated by whitespace or a comma. (string, up to 100000 characters)
- oldDomain
- domain mode: the old domain, e.g. old-site.com. (string, up to 253 characters)
- newDomain
- domain mode: the new domain, e.g. new-site.com. (string, up to 253 characters)
- domain
- https, www-add and www-remove modes: the site's domain, e.g. example.com. (string, up to 253 characters)
- https
- Use https:// in redirect targets for domain and www modes. (boolean, default true)
curl https://pithlab.com/api/v1/tools/htaccess-redirect-generator \n -H "Authorization: Bearer $PITHLAB_KEY" \n -H "Content-Type: application/json" \n -d '{"mode":"bulk","pairs":"/old-page.html /new-page\n/blog/2019/hello /blog/hello"}'Example response
{
"ok": true,
"result": {
"apache": "RewriteEngine On\nRewriteRule ^/?old-page\\.html$ /new-page [R=301,L]\nRewriteRule ^/?blog/2019/hello$ /blog/hello [R=301,L]\n",
"nginx": "# Inside your server { } block\nlocation = /old-page.html {\n return 301 /new-page$is_args$args;\n}\nlocation = /blog/2019/hello {\n return 301 /blog/hello$is_args$args;\n}\n",
"errors": [],
"warnings": []
}
}