🔐 API Permissions
The Redirects addon exposes a public API endpoint that your frontend can use to fetch redirect rules. This requires proper permissions configuration.
Setting up Public API Access
For your frontend application to access the redirects API endpoint.
Configuration Steps
- Go to Strapi Admin → Settings → Users & Permissions plugin → Roles.
- Select the role (e.g., Public or Authenticated).
- Under Webtools-addon-redirects section.
- Check Redirect: find.
- Click Save.
What it enables
- Access to
GET /api/webtools/redirectsendpoint - Required for: Frontend redirect implementation
Without this permission, you'll get a 403 Forbidden error when calling the redirects API from your frontend.
Access via API Tokens
In addition to the Users & Permissions plugin (for public and authenticated users), you can also use API Tokens for programmatic access to the redirects endpoint.
When to use API Tokens
- Build-time data fetching: Static site generators (Next.js, Gatsby, etc.)
- Server-to-server communication: Backend services fetching redirect rules
- CI/CD pipelines: Automated testing or validation of redirects
- Webhook handlers: External services that need to check redirects
Creating an API Token
-
Go to Strapi Admin → Settings → API Tokens.
-
Click Create new API Token.
-
Configure the token:
- Name: e.g., "Frontend Build Token" or "Redirects API Access"
- Description: Optional description of the token's purpose
- Token duration: Unlimited, 7 days, 30 days, or 90 days
- Token type: Choose based on your needs:
- Read-only: Can only fetch data (recommended for redirects)
- Full access: Can create, update, and delete (use with caution)
- Custom: Fine-grained permissions (see below)
-
Click Save and copy the generated token immediately (it won't be shown again).
Configuring Custom Permissions for API Tokens
For better security, use Custom token type with specific permissions:
- Select Custom as Token type.
- Scroll to Webtools-addon-redirects section.
- Enable only the permissions needed:
- find: Allows
GET /api/webtools/redirects(✅ recommended) - findOne: Allows fetching a single redirect by ID
- create, update, delete: Only enable if programmatic management is needed
- find: Allows
Use Read-only tokens or Custom tokens with only find permission enabled for frontend applications. Never expose tokens with write permissions in client-side code.
Using the API Token
Include the token in the Authorization header when making requests:
curl -H "Authorization: Bearer YOUR_API_TOKEN" \
"http://localhost:1337/api/webtools/redirects"
Next.js example (server-side):
// app/[[...slug]]/page.tsx or pages/[[...slug]].tsx
export async function generateStaticParams() {
const response = await fetch('https://your-strapi.com/api/webtools/redirects', {
headers: {
'Authorization': `Bearer ${process.env.STRAPI_API_TOKEN}`,
},
});
const redirects = await response.json();
// Process redirects...
}
Important: Store API tokens in environment variables (.env.local), never commit them to version control.
Testing API Access
Test with Public/Authenticated role
# Without authentication (requires Public role permissions)
curl "http://localhost:1337/api/webtools/redirects"
# With user JWT token (requires Authenticated role permissions)
curl -H "Authorization: Bearer USER_JWT_TOKEN" \
"http://localhost:1337/api/webtools/redirects"
Test with API Token
curl -H "Authorization: Bearer YOUR_API_TOKEN" \
"http://localhost:1337/api/webtools/redirects"
Expected response:
{
"data": [
{
"id": 1,
"source": "/old-page",
"destination": "/new-page",
"statusCode": 301,
// ...
}
]
}
After making permission changes, restart Strapi and clear your browser cache if needed.
Troubleshooting
403 Forbidden Error
Problem: Getting 403 when calling the API endpoint.
Solutions:
- Verify the correct role (Public/Authenticated) has
findpermission enabled - If using API token, verify it's valid and has correct permissions
- Restart Strapi after permission changes
- Check that the token hasn't expired
API Token not working
Problem: Valid token returns 401 Unauthorized.
Solutions:
- Ensure token is included in
Authorization: Bearer TOKENheader - Verify token hasn't expired
- Check token type has necessary permissions (not Read-only for write operations)
- Regenerate token if needed
CORS issues in frontend
Problem: Browser blocks API requests.
Solutions:
- Configure CORS in
config/middlewares.js:
module.exports = [
// ...
{
name: 'strapi::cors',
config: {
origin: ['http://localhost:3000', 'https://your-frontend.com'],
},
},
];