The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Rewrite Rule Slim 2

Madley's Avatar

Madley

24 Dec, 2015 11:57 AM

I'm on Slim Framework 2.
I need to add "v1" to the path url in case it is not present.
So:

http://www.example.com/products?param=1 -> http://www.example.com/v1/products?param=1

I must use rewrite rule and not redirect, 'cause I need to preserve POST and GET data.
So I've added the following .htaccess:

RewriteRule !^/?v1(/.*)?$ /v1%{REQUEST_URI} [NC,L]

If I print:

$this->app->request->getPathInfo();

I get the path missin 2 characters, so:

http://www.example.com/v1/oducts?param=1

Slim 3, works fine, but I can't upgrade at the moment. So, what am I missing here? Many thanks.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac