So the URL structures go something like:
Categories: website.com/shop/dresses/
Subcategories: website.com/shop/dresses/homecoming
Product: website.com/shop/dresses/homecoming/name-of-product
I would like to change the url structures to look like this:
For category and subcategory: website.com/category/dresses/homecoming
Product: website.com/dresses/homecoming/product-name
Basically, replace âshopâ with âcategoryâ for categories and subcategories. For the product, just remove âshopâ from URL.
How can I change the URL of subpages? Can you give me an example? I tried doing this myself using the documentation provided for routes but Iâm a bit confused and I wasnât able to get it to work the way I want.
Yes, basically, but only for the product pages and for the categories/sub-category replace âshopâ with âcategoryâ.
Like this:
(Replace âshopâ with âcategoryâ)
Category old url: website.com/shop/(category-name)/(subcategory-name)
Category new url: website.com/category/(category-name)/(subcategory-name)
(Remove âshopâ from url completely)
Product old url: website.com/shop/(category-name)/(product-name)
Product new url: website.com/(category-name)/(product-name)
A route that listens on category/(:all) and returns return page('shop/' . $category)
A route that simply âremovesâ the shop folder from the URL for the product pages. You can use the blog example from the routing docs for this.
Then you need to change the links to the products so that they use the correct URI scheme.
However please note that rerouting can lead to duplicate content if you donât redirect the other URLs and it can also lead to unexpected results in other parts of your site since you potentially override top-level pages with the same name as a shop category.
Thanks, I got it working. One more question, since Iâm a little confused on what routers are suppose to do exactly, arenât they suppose to also change the links on pages too?
The routing is working how itâs suppose to but the links on the website are still the same as they were before.
For example, on my websites menu, the links to the category pages should now be website.com/category/category-name but they still show up as website.com/shop/category-name
The router does not create URLs, the original URL still exists, it is only redirected. Therefore, you will have to adapt your links in your menus if you want them to show the ânewâ URL.
Edit: See this post for using a page model to automate this: