我需要在 Laravel 中实现下面的 htaccess 通配符 URL 重写规则。
实际网址应该是这样的
与上述 URL 关联的 htaccess 规则。
RewriteRule ^/products/([A-Za-z\d\-\.]+)/([A-Za-z\d\-\.]+)$ product.php?category_name=$1&product_name=$2&retype=0 [L]
Laravel 路线
Route::get('/product-category/product-name.html', [ProductPageController::class,'index']);
我需要在每个 URL 中保留 .html 扩展名。
如果只想加载html文件:
{!! $page !!}
Route::get('{any}', function ($any) {
return view('welcome' , ['page' => file_get_contents(__DIR__."/resources/pages/{$any}.html")]);
});
现在,如果您调用
http://test.com/products/mobile-phones/phone-model.htmlurl,将加载
phone-model.html
目录中的resources/pages/products/mobile-phones/
文件。