ash-jc-allen / short-url

A Laravel package for creating shortened URLs for your web apps.
MIT License
1.27k stars 161 forks source link

Short URL Redirection Issue and Configuration #292

Closed bulentsakarya closed 3 months ago

bulentsakarya commented 3 months ago

If I update the key value in the short URL, the redirection doesn't work.

That is: https://site.com/l/k4x9e it works. https://site.com/l/linux doesn't work. It gives a 404 error.

The prefix value in the short-url.php file in the config folder is as follows: 'prefix' => 'l',

In the web.php file in the routes folder, there is a definition: Route::get('/l/{shortURLKey}', '\AshAllenDesign\ShortURL\Controllers\ShortURLController');

ash-jc-allen commented 3 months ago

Hey @bulentsakarya! I'm sorry to hear you're having issues with the package.

Please could you give me some steps to reproduce the issue? 😄

bulentsakarya commented 3 months ago

I'm developing a service with Laravel 11 where members can register their Google Business accounts. I installed the short URL package you developed to make it easier to use for Google review URLs.

Since the package also allows customizing the value in the short URL, I enabled my members to change this URL value with a value they specify themselves.

I perform the update operation with the following code:

public function updateKey(int $id, array $data)
{
    $googlePlace = $this->getById($id);
    $shortUrl = $this->shortURL::where('default_short_url', $googlePlace->short_review_url)->firstOrFail();
    $newShortUrl = $this->shortURLService->updateShortURLKey($shortUrl, $data['new_key']);

    $googlePlace->update([
        'short_review_url' =>  $newShortUrl->default_short_url
    ]);

    return $googlePlace;
}

I don't have any issues updating the short URL value.

The url_key and default_short_url values in the short_urls table are updated according to the desired value. Ekran görüntüsü 2024-07-30 182812

To keep the URL from getting too long, I set the prefix value to 'l'. I changed the prefix value in the config folder to 'prefix' => 'l'.

I also wrote the route you specified in the web.php route file. Like this:

use AshAllenDesign\ShortURL\Controllers\ShortURLController;
Route::get('/l/{shortURLKey}', ShortURLController::class);

As I mentioned in my first message, the short URL redirects with the initially created value. However, if I change the short URL value, it doesn't redirect with the new value.

ash-jc-allen commented 3 months ago

Thanks! This sounds like a bizarre issue that might be something specific to your application. Would it be possible for you to reproduce the issue in a fresh Laravel app and give me access to it so I can investigate it, please? 😄

bulentsakarya commented 3 months ago

I've sent a demo data to your email. It works now. Did you do anything?

And changed key, it doesn't work anymore.

ash-jc-allen commented 3 months ago

Thanks for sending a link to the site in the email. But, please could you reproduce the issue in a fresh Laravel app? That way, we can rule out it being an issue with your application, and confirm it's an issue with the package 🙂

bulentsakarya commented 3 months ago

The problem was due to timezone settings. When I changed the URL, the new URL didn't appear active. More precisely, there was still time until the activation hour. When I adjusted the timezone value, the problem was resolved.