Home  >  Article  >  Backend Development  >  How does nginx rewrite static URLs into dynamic ones?

How does nginx rewrite static URLs into dynamic ones?

WBOY
WBOYOriginal
2016-12-01 00:25:591157browse

I used lumen to make the api interface. The url is static, similar to this:
https://www.foo.com/api/v1/ar...
The id here is the required parameter.
But when I call the interface, I use this URL format to pass parameters:
https://www.foo.com/api/v1/ar...

Can I directly change the url format to support it in laravel or lumen? Inquiry form?

Or implement it by rewriting it in the rewrite method of nginx. How to rewrite it specifically?
Thank you! !

Reply content:

I used lumen to make the api interface. The url is static, similar to this:
https://www.foo.com/api/v1/ar...
The id here is the required parameter.
But when I call the interface, I use this URL format to pass parameters:
https://www.foo.com/api/v1/ar...

Can I directly change the url format to support it in laravel or lumen? Inquiry form?

Or implement it by rewriting it in the rewrite method of nginx. How to rewrite it specifically?
Thank you! !

This does not require URL rewriting and routing

<code>Route::any('api/v1/article', function(Request $request){
    $id = $request->input('id');
    if (empty($id)) return 'parameter "id" invalid. ';
    return redirect('api/v1/article/'.$id);
})

Route::any('api/v1/article/{id}', 'ArticleController@index');</code>

Thanks for the invitation.

<code>
https://laravel-china.org/topics/688
</code>

Set up the routing.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn