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

davidalavely's avatar

Weird URL issues

I have a site running Laravel 6 with PHP 7.1. It is housed on Digital Ocean and I use Forge to manage it. I have directed another domain to the server; some of my links show up with the main URL and others show the redirected URL. I am using a getLink() to generate all my in-site URLs and I can't figure out where my problem is. Is the problem with my server setup, domain setup, or my code?

0 likes
6 replies
vincent15000's avatar

You should generate the links with the route() helper.

Do you have an example of code ?

1 like
davidalavely's avatar

I am using the routes helper as you suggested. The core of the route helper is: function route($name, $parameters = [], $absolute = true) { return app('url')->route($name, $parameters, $absolute); }

the getLink() function I am using is here:

public function getLink($locale_override = null){ if ($locale_override !== null) { $locale = $locale_override; } else { $locale = app()->getLocale() != 'en' ? app()->getLocale() : null; } $cache_key = config('dremed.site_id').''.env('APP_ENV').''.$locale.'_'.'category:'.$this->id.'.link'; $link = Cache::tags(['all', 'category:'.$this->id, 'link'])->rememberForever($cache_key, function () use ($locale) { if (! empty($this->fresh()->override_link)) { return $this->fresh()->override_link; }

        if ($locale == 'en') { 
            $locale = null;
        }
        if ($this->fresh()->type == 1) { 
            return route('frontend.catalog.category.slug-brand', [$this->slug, $locale]);
        } else {
            if ($locale === null) {
                if ($this->fresh()->type == 3) { 
                    dump('1');
                    return route('frontend.catalog.category.slug-supply-category', [$this->slug, $this->id]);
                } else {
                    dump('2');
                    return route('frontend.catalog.category.slug-category', [$this->slug, $this->id, $locale]);
                }
            } else {
                if ($this->fresh()->type == 3) { //supply
                    return route('frontend.catalog.category.id-supply-category', [$this->id]);
                } else {
                    return route('frontend.catalog.category.id-category', [$this->id, $locale]);
                }
            }
        }
    });
    return $link;
}

An example of what is happening is shown with the link below. Some of the links are avantehs.com. others are dremed.com. https://avantehs.com/c/patient-monitors/24

1 like
jlrdw's avatar
jlrdw
Best Answer
Level 75

@davidalavely I hope someone doesn't say I am off topic here.

@jeffreyway I am only inserting here due to security.

@davidalavely see https://laracasts.com/discuss/channels/laravel/unknow-script-is-injecting-when-the-page-is-loading?page=1&replyId=920096

Where laravel 6 may need checked for security.

Sorry if off topic, but security is important.

Put the image on imgur, and give link to it. Imgur is a known site many here use.

2 likes
davidalavely's avatar

I have been able to resolve this problem, partially with an update to laravel 8, and getting a better understanding of the redirects within the Forge System.

1 like

Please or to participate in this conversation.