Laravel 5 Redirect Problem

I am working my way through the Laracasts course Laravel 5 Fundamentals at Things were going great until I got partway through lesson 13: View Partials and Form Reuse and hit a wall.

I use Xampp (I gave up trying to get Homestead working for now, because I really don’t have the time it is taking me to figure out what is going wrong with it right now).

When I type the URL localhost/L5Project/public/articles which should take me to a listing of all the articles in the database, Firefox v.39.0 keeps redirecting me to localhost/articles and then I get a 404 error. I’ve tested it in Chrome and Internet Explorer and do not have that problem there.

I have tried clearing my cache and cookies, an triple-checked my code, with no success. Can someone please help me to figure out where to look to find what is causing this problem? I asked in the Laravel discussion area several days ago, but no-one seems to be responding.

You need to set-up a vhost (virtual host) that specifies the public directory path as the site root. I don’t remember how to do that windows. All this type of stuff is super simple on a vm which is why using a vm is SO highly recommended. You are probably going to keep running into dev ops problems like this especially on windows if you’re not using a linux vm/ familiar with basic server admin/networking.

Sorry I was slow in responding - a really busy few days!

I totally intend to get back to trying to get Homestead set up, but can’t right now.

In the meantime, can anyone explain why this redirecting is happening with Firefox, but not with any of the other browsers? I hate loose ends. :smile: Thanks.

Hi WebMachine,

Often this kind of problem occurs when you run a site from a sub-folder when it’s expecting to be run from the web root. In this case, probably the URLs are relative to the root (eg. ‘/articles’) which is why you’re ending up at localhost/articles. Not sure why the other browsers aren’t behaving in the same way, as I’d have expected them to interpret the URL in the same way.

As oddz suggested, setting up a virtual host on XAMPP would resolve this. I found this tutorial which seems to explain the process better than I probably could, although there’s no date on it, so there’s a small chance the settings might be slightly different for the version of Apache that you have installed. If you run into problems, you’re welcome to post back here and I’ll see what I can do to help.

Thanks, @fretburner. That looks just like what I need. I’m going to try setting it up tonight and will definitely ask if I run into problems.

I just need one clarification before I do this: It sounds like I can set up more than one ‘domain’ (one for each project) and map it to the IP address . Is that right? And the different projects won’t conflict with each other?

Also, will this virtual host interfere with any of my other projects that are in localhost right now? I have a lot of stuff in there that I really don’t want to lose. (And yes, I’ll make another backup before I start this process).

Absolutely, you can set up as many as you want. Some people like to use a convention such as sitename.local to distinguish locally hosted sites from public ones.

No, your current setup should continue to work as-is.

with a pure installation of L5/L5.1 you can use their artisan command to run your page(s).
change to your working directory, eg /htdocs/myapp
in the commandline type in: php artisan serve
and you are all set to go.
calling your page would be: localhost:8000/articles

@frezno, I got your suggestion to work, until I had to use the command line for other things. It’s almost like the built-in Laravel server hijacked it, and I couldn’t enter any more commands.

@fretburner, after a few false starts and Googling issues like Windows 7 not letting me edit the hosts file, I was able to get the virtual host set up and it seems to be working smoothly.

I’ll let you know if anything goes wrong. Thanks for all your help.

I know. Aaarrgghh!!!
You have to “as administrator” (right click) a lot of times with Windows Security to get perms.

Everything web dev related is a struggle on windows unless you’re using .NET.

Not wanting to veer from the original topic of this thread, but I’ve studied with c# using Visual Studio, and I’ve studied CLI, linux and ubuntu, but I’m just not ready yet to make the switch from PHP/mySQL on Windows, even if it is a pain. There are so many things out there to learn, I need to keep something that is familiar as a security blanket, even if it creates so many frustrating issues.

I know, you have to stop the service if you want to work on your command line again.
Usually it shouldn’t be a problem unless you don’t want to switch very often to you localhost.

But as already said, best choice is installing a vhost.
There shouldn’t be a problem to edit Apaches config files as long as you open it with admin rights which as well has already been mentioned.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.