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

divinulledivi's avatar

Is it bad practice to use absolute URL in an anchor tag?

I am creating a website with multiple subdomains (forums). On my home view I want to list all discussions from all subdomain forums. I can't use a relative URL because I need to prefix the route with the subdomain. I found a way that works -

<a href="http://{{$discussion->forum->slug}}.frm.test/discussion/{{$discussion->id}}/{{$discussion->slug}}">{{$discussion->title}}</a>

But something about this feels wrong. Is there a better way to achieve this or is this ok?

0 likes
2 replies
grenadecx's avatar
Level 7

Absolute urls are fine. In fact laravel usually generates absolute urls when you use their functions, unless you specify you want relative.

In your case I think you should consider named routes. So you can generate your urls like this instead:


<a href="{{ route('discussion', ['forum' => $discussion->forum->slug, 'id' => $discussion->id, 'slug' => $discussion->slug]) }}">{{$discussion->title}}</a>

Using named routes will allow you to change the structure of your routes a lot easier and will be less prone to break if you decide you want to change the base structure and it's a lot easier to remember.

https://laravel.com/docs/5.8/routing#route-group-name-prefixes

Snapey's avatar

Also, you don't want to be hardcoding http into your own URLs because you might want to deploy the site on https

1 like

Please or to participate in this conversation.