0

Laravel 8 documentation says that I can use forward slashes as part of an URL parameter:

https://laravel.com/docs/8.x/routing#parameters-encoded-forward-slashes

It's not working for me. I did:

Route::get('/testslash/{param}', function($param) {
    return $param;
})->where('param', '.*');

Calling it with /testslash/test%2Ftest

Results in a 404 page not found.

When using a parameter without slash, the page is loaded showing the parameter value as expected.

Do I maybe have to set another particular laravel option to make this work?

drakanor
  • 107
  • 8
  • are you using `/` or `%` between your parameter text? – Faizan Ali Jan 19 '22 at 16:01
  • `Encoded forward slashes are only supported within the last route segment.` – Faizan Ali Jan 19 '22 at 16:06
  • I don't see a problem in the code. I, in fact, tried the same function, and it worked very well at my end. Do you have any configuration which can lead to this issue? – Rakesh Kumar Jan 19 '22 at 16:10
  • @FaizanAli the parameter contains the slashes in urlencoded form (%2F). And it is the last route segment. – drakanor Jan 19 '22 at 16:14
  • @RakeshKumar With what URL did you test it in particular? – drakanor Jan 19 '22 at 16:16
  • @RakeshKumar Not in Laravel. My Apache2 vhost config looks like this (as recommended for Laravel): RewriteEngine On # Handle Authorization Header .... # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] # Send Requests To Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] – drakanor Jan 19 '22 at 16:23
  • @RakeshKumar is right, there is no error in your code. – Faizan Ali Jan 19 '22 at 16:26
  • 1
    Are you using Apache? https://stackoverflow.com/questions/4390436/need-to-allow-encoded-slashes-on-apache – Álvaro González Jan 19 '22 at 16:57
  • @ÁlvaroGonzález Yes I do. Thanks for the link, I'll try the NE flag for RewriteRule next time I'm on the server. – drakanor Jan 20 '22 at 17:13

1 Answers1

-1

I tried this in my laravel 8 project. You should pass as param, the Slash (/) not it's encoding 2%F.

Route::get('/testslash/{param}', function($param) {
    return $param;
})->where('param', '.*');

so the param you pass is test/test and not test2%Ftest.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Juni
  • 27
  • 6
  • That's not what I want to do. The slash is part of the url parameter and not a url delimiter and is therefore encoded. – drakanor Jan 20 '22 at 17:10