Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

brtbrt's avatar

Best way to list multiple tags in URL?

I want to capture multiple tags in a single URL (using Spatie Laravel Tags package), there are various ways to do so, what is best practice?

Option #1: http://example.com/tags/lorem,ipsum,dolores

Option 2: http://example.com/tags?['lorem',ipsum'dolores']

Option 3: http://example.com/tags?tags[]=lorem&ipsum&dolores

Option #1 allows to create an array using explode() based on comma. Option #2 requires json_decode(). Option #3 captures the array which can immediately be used.

The input will need to be validated with regex [a-z0-9-]+.

My vote would go to #1 because it'll be easier to print the URL in blade - a simple implode(), but curious about your thoughts. I haven't considered SEO in this yet, but my feeling is #1 would perform best as well.

0 likes
6 replies
automica's avatar

option 1 would be better as http://example.com/tags=lorem,ipsum,dolores

option 3 is a bit weird. would be better as

http://example.com?tags[]=lorem&tags[]=ipsum&tags[]=dolores

if you look at

request()->all()

you'll see that come through as an array of tags.

if there is no seo consideration then choose whatever way you like.

for seo, think what the data the page is returning.

eg http://example.com/articles?tag=foo I would expect all articles tagged with foo

eg http://example.com/articles?tag=foo,bar I would expect all articles tagged with foo and bar

for your url

http://example.com/tags/lorem,ipsum,dolores

i`ve no idea. its not going to tags with lorem,ipsum,dolores.

as for :

my vote would go to #1 because it'll be easier to print the URL in blade

if you printing a URL in the blade it makes no difference which method you are using as you will be printing it by a helper method or a getter on the resource. If you url needs to humanly parsable then go for the easiest one for a human to construct.

Here's an blog post which also can't make up its mind :D https://medium.com/raml-api/arrays-in-query-params-33189628fa68

1 like

Please or to participate in this conversation.