1

I currently have a WAMP server running with 2 sub-folders, one contains a Laravel project with a public folder.

I don't want to create a .htaccess file to redirect from /laravel to /laravel/public.

Instead I want to change the redirection in the vhost file from Apache. I know how to redirect the root folder of WAMP (www) to Laravel's public folder, but what I want is:

  • Whenever I go to WAMP's root, I'll still see a list with folders like it normally does.

  • When I go to the /laravel directory it gets automatically redirected to /laravel/public.

This is how I currently have it in the httpd-vhosts.conf file.

enter image description here

But this does not seem to work for me and when I switch the place of those 2 I'll get automatically sent to the public folder without being able to view the www folder.

I already tried to google it but only ended up with how to redirect the www root to a sub-folder.

So my question is: How to redirect the root of a sub.folder to a i.e. public folder?

Spoody
  • 2,852
  • 1
  • 26
  • 36
ArchBacon
  • 28
  • 11

1 Answers1

1

You have named both your Virtual Hosts localhost thats not the point of a Virtual Host. Change the laravel projects VH like this

<VirualHost *:80>
    ServerName laravel.test
    ServerAlias www.laravel.test

    . . . Leave other code as you had it

</VirtualHost>

Now go to your HOST file and add the domain name laravel.test like so

edit C:\Windows\System32\drivers\etc\hosts

It should look like this

127.0.0.1 localhost 
127.0.0.1 laravel.test

::1 localhost 
::1 laravel.test

Then restart the dnscache or reboot.

>net stop dnscache
>net start dnscache

NOTE: You shoudl never make localhost available to the internet so change this line back to what it was originally in the localhost VH definition

Require local

Also unless you actually want to make the laravel project availaibe on the internet do the same for that VH or if you want to make it available on your internal network set the Require like this

Require ip 192.168.1

Assuming your subnet starts with 192.168.1 yours maybe different!

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • I have placed `Require ip 192.168.0` in the VH of localhost and now i cannot enter localhost on my PC. I can however enter it using a device on the same network. My local ip of my PC is `192.168.0.105`. Entering laravel.test works perfectly! Thank for that @RiggsFolly – ArchBacon Apr 16 '18 at 09:53
  • The `localhost` VH should be `Require local` Its not a good idea to access that from anywhere else as things it does tend to reference `localhost` and therefore wont work when run from another PC as `localhost` always means **this PC** and links will attempt to look on the other PC for code which of course wont exists on the client PC's – RiggsFolly Apr 16 '18 at 10:49
  • Alright. I can now enter the laravel folder by going to `laravel.test` as a webadress. But i dont know how i can see that project from other devices i.e. my phone. I do not have the need to get access to individual files. But i want to use the project as an API. Are there any other setting i need to change for that because when i go to my "API" url i get no permission because it redirect to `localhost` (which is using `Require local`. Sorry if this is a stupid question @RiggsFolly – ArchBacon Apr 16 '18 at 21:58
  • Here [is my solution to that problem](https://stackoverflow.com/questions/43016713/wampserver-access-server-from-mobile-phone/43018881#43018881) have a look at it and see if it helps – RiggsFolly Apr 16 '18 at 23:35
  • Works like a charm! Thank a lot for your help @RiggsFolly – ArchBacon Apr 17 '18 at 17:21
  • I dont have enough rep for that :/ – ArchBacon Apr 18 '18 at 09:32