skip to Main Content

Hello Laravel Experts,

(I am newbie to laravel)

for my Laravel application, I want to change my path from

/ to /quote,

i.e. the current url –

https://example.com/  --> https://example.com/quote/

I have changed it at proxy level, but then the images, css, js and livewire all fail.

Then changed the code for images, js and css as below –

- read as /images/abc.png => /quote/images/abc.png -

and the images folder moved from –

 public/images  => public/quote/images

and same for js and css
etc.

However, this doesn’t work with livewire (livewire.js, or /livewire/update)

In other words, is there a way to change the root URL from / to /quote – without having to meddle with code? may be add a new route – at core level?

Pls advice / code lines

same as described above

2

Answers


  1. Regular expression constraints might be what you’re looking for.
    https://laravel.com/docs/10.x/routing#parameters-regular-expression-constraints

    It would look something like the code below.

    Route::get('/{any}', function (string $any) {
        redirect('/quote' . $any, 302);
    })->where('any', '.*');
    
    Login or Signup to reply.
  2. Do you really need to change the URL for assets (css, js, images, etc)? If not then you could just add prefix and group to your route.

    Route::get('/', function () {
        return redirect()->route('index);
    });
    
    Route::prefix('quote')->group(function () {
        Route::middleware('auth')->group(function () {
            // Authenticated routes
        });
    
        Route::get('/', [IndexController::class, 'index'])->name('index'); // top/LP
    
        // Not Authenticated routes
    });
    

    URL will be: https://example.com/ --> https://example.com/quote/

    Everytime users access https://example.com/ they will be redirected to https://example.com/quote/

    ADD

    If you want to move your assets to /quote then move all assets to public/qoute folder. Though you will need to update how you use your assets like the following:

    1. {{ asset('js/app.js') }} to {{ asset('quote/js/app.js') }}
    2. {{ URL::asset('js/app.js') }} to {{ URL::asset('quote/js/app.js') }}
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search