简体   繁体   English

有什么办法可以改变 Laravel 5.5 中的 url 吗?

[英]Is there any way to change url in Laravel 5.5?

I am developing a site with Laravel 5.5我正在使用 Laravel 5.5 开发一个站点

I am going to hide the product slug when customers visit single product page.当客户访问单个产品页面时,我将隐藏产品标签。

original url: http://localhost/laravel/product/category-name-product-slug (this is product slug in database)原始 url: http://localhost/laravel/product/category-name-product-slug (这是数据库中的产品 slug)

must be changed to: http://localhost/laravel/product/category-name.php (or html)必须改为: http://localhost/laravel/product/category-name.php (或html)

The problem is that I have to send the product-slug to controller so that know about what product is needed instead of product ID.问题是我必须将产品标签发送到 controller 以便知道需要什么产品而不是产品 ID。

Also I have to show category name(this must be substring of product-slug: substr($product_name, 0, -10)) on browser url.我还必须在浏览器 url 上显示类别名称(这必须是 product-slug: substr($product_name, 0, -10) 的 substring)。

How can I solve this problem?我怎么解决这个问题?

If you can't put it in the path you'll have to use a query string.如果不能将它放在路径中,则必须使用查询字符串。

Retrieving Input From The Query String从查询字符串中检索输入

e.g. http://localhost/laravel/product/category-name.php?product-slug=product-slug

and if you have to do that you might not lose any seo by also passing the category and product ids in the query string.如果您必须这样做,您可能不会通过在查询字符串中传递类别和产品 ID 来丢失任何 seo。

I have solved this problem by using form.我已经通过使用表单解决了这个问题。

I have created a form in blade and made its method to POST.我在刀片中创建了一个表单并将其方法设置为 POST。

Defined a hidden variable to represents product slug, and then render a virtual slug name (substring of product slug) to route.定义一个隐藏变量来表示产品 slug,然后渲染一个虚拟 slug 名称(产品 slug 的子字符串)来路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM