Routing html extension SOLVED

Hi,

I used to have some routing setup on a server that had something like someurl.com/panel.html

No i’ve converted all into Slim. What used to be inside of panel.html is inside of /panel route

My question is to know if is possible to redirect the route /panel.html to /panel using slim. I’ve tried a few options (including middleware) but did not work.

I know we can do it using htaccess or nginx/apache, but I dont have access to that.

Is there any proper way or using slim to do it?

thanks

Of course if you want to there is no reason why you can’t make the route /panel.html in Slim as well. But if /panel is still desired, you can do something like this.

$app->get('/panel.html', function ($request, $response, $args) {
    return $response->withRedirect('/panel', 302);
});

Or alternatively:

$app->get('/panel.html', function ($request, $response, $args) {
    return $response->withStatus(302)->withHeader('Location', 'http://example.com/panel');
});

Finally, even though you don’t have access to Apache, so long as you have the ability to use .htaccess files you could do the redirect there rather than within Slim.

1 Like

Hi, thanks for the fast reply.

I’m almost sure that you cannot do that, slim (v3) does not recognise the . In that case it will only get /. I think I’ve try that before, but I will give another shot.

thanks

It works fine for me.

$app->get('/panel.html', function ($request, $response, $args) {

I’ve tested today again… that does not work at all.

Having /panel.html just is the same has /

Need to find another way.

There is no reason why that shouldn’t work and it is fully supported in Slim. Show us some code (at least your route definition and any webserver routing) and we will have a look.

Sry I was mistaken. In general works, but in my case I probably have some kind nginx configuration probably index index.html index.php that is not allowing it.

I tried redirecting with a different extension name index.xxx and it worked. I will have to come back to this later.

But thanks