Quick question,
EDIT: I do not know how to access other routes besides '/'
Here are the routes I want to access
Route::get('/', 'HomeController#index');
Route::get('users', 'UserController#index');
Route::get('foo', function()
{
return 'Hello World';
});
Here is my routes. Via php artisan routes
I can successfully access localhost/cartraderlaravel/public
It takes me to HomeController#index
when I try to access foo or users I get
I have tried
localhost/cartraderlaravel/public/users
localhost/cartraderlaravel/users
localhost/cartraderlaravel/foo
localhost/cartraderlaravel/public/foo
All of these return a "Not Found" error. Help anyone?
You should point your root directory to cartraderlaravel/public in WAMP so that you need not to visit localhost/cartraderlaravel/public. To do that in WAMP follow :
Click on WampServer icon in taskbar
Select Apache > httpd.conf from the pullup
Search for the term “DocumentRoot”
Change the DocumentRoot path to your custom directory
Search again for “DocumentRoot” again same procedure
Save your changes and “Restart All Services”
Further research shows this is a common problem with WAMP. Something to do with Apache settings. I have moved to using a virtual network and everything works now
Related
I've encountered a problem while creating simple apps with Laravel on IIS.
When I create a new Laravel application I can see the Laravel welcome page just fine.
If I create another view in the same folder as the welcome.blade.php (test.blade.php for example), and set up the route for that in routes/web.php I can't navigate to that page in browser. EDIT: When I attempt this I get a 404.
My web.php is as follows:
<?php
Route::get('/', function (){
return view('welcome');
});
Route::get('/test', function (){
return view('test');
});
At first I thought that perhaps the project was not reading web.php, but when I run php artisan route:list the test route is listed.
I thought perhaps that my view didn't work, so I renamed it as welcome.blade.php and that loaded up fine. I just seem to be unable to add a route to any view or anonymous function that isn't mapped to welcome.blade.php
I tried adding a static route.php file into the app directory with the same code, but that made no difference to the result.
I'm sure I must be missing something basic, but I can't seem to put my finger on where I've gone wrong. Would massively appreciate any help you might be able to offer. Thank you.
Right I worked out where I went wrong. I hadn't run artisan serve. Very simple.
If you're having this problem, try navigating to your application root in cmd and then try
php artisan serve
Then navigate to your page using that information.
Thank you to everyone who posted, massively appreciated.
You need to install Url Rewrite in your terminal. Then import the .htaccess file located in your project/public folder.
To install Url Rewrite, you need to install Web Platform Installer (WPI). Once installed, open WPI then search for the keyword "Url Rewrite", then install the first item in the result. Once the download is finished, Url Rewrite will be available in your IIS Manager
I think IIS server maybe blocks test url.
IIS server has such features.
Before time, I remember that I used IIS blacklist url feature.
You may check IIS url block feature.
I have a laravel project which I run from my local apache server directory.
The link for accessing this project is
www.localhost/project.dev/public/index.php
And I have a navigation menu
After I have set the APP_URL in .env file to
http://localhost/blog.dev/public/index.php/
I get no problems while navigating through the About and Contact pages in the project but when I access the Home page the browser goes to the
http://localhost/
but not to the
http://localhost/blog.dev/public/index.php/
How can I fix it? Here are my routes:
Route::get('/', 'PagesController#getIndex');
Route::get('about', 'PagesController#getAbout');
Route::get('contact', 'PagesController#getContact');
I think the best way is to setup a vhost in apache. if you want to work like this in your .env set the APP_URL= http://localhost/blog.dev/public/
Run php artisan serve in command line. The laravel buil-in server will active. And you will able to access your laravel application using correct url as like http://localhost:8000 try this and let me know if you have any problem.
I have installed fresh copy of laravel 5.3.
I have the following code in my route/web.php.
Route::get('/', function () {
return view('welcome');
});
Route::get('welcome', function () {
return view('welcome');
});
when i hit localhost/project/public in the browser i can see laravel welcome page.
But when i hit localhost/project/public/welcome then 404 Not Found comes up where i should get the same laravel welcome page.
Am i forgetting something ?
Laravel is case insensitive, so if you created the project with one of these will not find the path.
Has your route file been cached? See what happens when you run:
php artisan route:clear
and try again.
I was having some trouble with this myself, so for anyone having trouble with getting a Laravel route to work:
Make sure your route is defined the correct way by running php artisan route:list Your route should show up, along with the method. (get, post, ...)
Enable mod_rewrite from the Apache settings so Laravel can map /uri to whatever you like.
Modify the .htaccess or Apache settings to allow url overrides: AllowOverride All If you are working on something like localhost/~username/yourproject, also check the username.conf file in /private/etc/apache2.
I'm not an expert in Apache settings, so feel free to correct or elaborate where needed.
goto htaccess in your laravel folder
after ( RewriteEngine On ) add this
RewriteBase /yourlaravel project name/public
example:
RewriteBase /laravel/public
I just installed laravel following the instruction on Larvel docs. I chose to use install via composer create project command.
In the routes. php i created a dummy route
Route::get('/', function(){
return 'Front Page';
});
When i access http://localhost/mysite/ It shows directory listing of mysite folder. However when i use http://localhost/mysite/server.php It runs my route closure.
I also tried alternate .htaccess code provided at Laravel's docs but that doesn't work either.
I want to remove the server.php from url.
Thanks in advance for help.
This behavior is expected and this is how Laravel works. The public folder is meant for assets and is also (supposed to be) the webservers root directory.
If you are working on localhost that is not the case and the root directory contains multiple projects.
In order to get rid of public you would have to change virtual host settings.
As mentioned here in the site.
The problem with doing virtual hosts is that other projects in localhost will become inaccessible.
So I just uploaded my site from my local dev environment to my server.
But there's a problem. Only the index page loads. I've mapped some
controllers to different routes like this:
//controller detection
Route::controller(Controller::detect());
//site routes
Route::get('/','site#index');
Route::get('about','site#about');
Route::get('blog','site#blog');
Route::get('downloads','site#downloads');
Route::get('products','site#products');
Route::get('shop','site#shop');
//admin routes
Route::get('login','admin#login');
//ajax functions
Route::get('loadnews/(:num)','ajax#loadnews');
Route::post('sendmessage','ajax#sendmessage');
Route::post('loadblog','ajax#loadblog');
Route::post('loadblogdetails','ajax#loadblogdetails');
Event::listen('404', function()
{
return Response::error('404');
});
Event::listen('500', function()
{
return Response::error('500');
});
Route::filter('before', function()
{
// Do stuff before every request to your application...
});
Route::filter('after', function($response)
{
// Do stuff after every request to your application...
});
Route::filter('csrf', function()
{
if (Request::forged()) return Response::error('500');
});
Route::filter('auth', function()
{
if (Auth::guest()) return Redirect::to('login');
});
And when I click on the links pointing to these routes, I've get a
simple Error: 324 (net::ERR_EMPTY_RESPONSE): from chrome.
How can I fix this?
The site currently located at: site
I was having a similar problem, and I resolved it deleting the line:
Route::controller(Controller::detect());
I'm using named Url's. Give it a try.
At least on my end I was able to fix this problem by adding. RewriteBase / to the .htaccess file. Now everything seems to be working properly.
Make sure you register the controller if you haven't.
Route::controller(array('site'));
If you're using Apache on your server, make sure mod_rewrite is on and configured as well as a decent .htaccess rule set, laravel comes with a pretty decent .htaccess for Apache servers.
Also make sure you have removed the 'index.php' base url from Application config.
These are probably the most common reasons why Routes don't work. You can also test your routes from the command line that makes this process a little simpler:
php artisan route:call get about
I had to put the root route, in your case :
Route::get('/','site#index');
at the bottom of the routes.php file
It appears you are using Linux, but in case this is applicable for future readers with the same issue:
For me, the issue was that I am running my app on Windows Server 2008 R2 and I hadn't set up the htaccess properly through my IIS Manager. I hadn't realized I needed to do this because for other sites, my htaccess files were working fine, but none of them were using mod_rewrite.
The solution was to install "IIS URL Rewrite Module 2", which I then could use from the IIS Manager, where I would choose to "Import" everything from the default htaccess file included with Laravel.
After that, all pages loaded, not just the index.