4

I've finished my laravel project and played it in a subfolder on my domain. https://example.com/swap

So the above is the root of my directory and when I go there, I do get the index. But now every link I press, I'm redirected to the root of my domain. So I'm getting: https://example.com/events/1 Instead of https://example.com/swap/events/1

Am I forced to change all URLs by hand in my files are is there a way my htaccess can always redirect to this 'swap' folder and place everything behind that?

I've tried using groups in my routes, without success.

Niknok
  • 51
  • 2
  • 4

4 Answers4

0

You need to direct your VHOST to laravel's public folder. This is done for security purposes. Ideally your laravel install is outside the public folder, thus you would have yourdomain.com contain your laravel install and rename your public folder to swap.

IF you really want the name swap in your routes you could use route prefix with groups.

ied3vil
  • 964
  • 1
  • 7
  • 18
0

Open .env File and Change Your App Url to https://example.com/swap/ and use routes as links of whole application
All Url's Will Work fine.

M Uzair Qadeer
  • 482
  • 1
  • 8
  • 19
0

When putting a laravel application in a subfolder. You need to modify your .htaccess for subfolder hosting. And add the following:

RewriteBase /swap

This way, the app knows when you go to route {{ url('/hello-world') }}, it will ultimately go to "/swap/hello-world"

0

Use url for all your links which are inside views folder:

  1. For subfolder link use:

<a href="{{url('swap/link')}}">Sub-Folder Link </a>

  1. For root folder links use this syntax:

<a href="{{url('index')}}"> Index </a>

There might arise issues with stylesheet and javascript in 'swap" sub-folder links with a 404 error. To fix that, use:

<script type="text/javascript" src="{{asset('js/app.js')}}">
<link rel="stylesheet" type="text/css" href="{{asset('css/app.css')}}">
m89ak47
  • 9
  • 1