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.
Related
Sorry if the title doesn't make sense. I will elaborate more here.
Background. This works on my local using valet but not on Ubuntu 18.04 Production. I am using Larvavel 6.18.7 and nginx verison 1.17.3 and have redirects using Certbot for http to https.
I thought it was an all round issue with the platform but have got it down to an issue with just a route to Route::post('/business', 'BusinessController#store');
I have been debugging for hours so I have now created some test pages to hopefully explain this better.
I have now have two Axios POST calls in a Vue Component but its actually just the business one.
axios.post('/business', {'q':"hello"})
.then(res => {
console.log(res)
})
.catch(error => {
console.error(error)
});
axios.post('/test', {'q':"hello"})
.then(res => {
console.log(res)
})
.catch(error => {
console.error(error)
});
The issue I am experiencing is the /business route when this is called I get a 301 Redirect. Laravel doesn't like the trailing / so thats why it is 403 but it shouldn't be redirected.
Both these go to the same place, i have placed these at the top of my routes to check that the business isn't called anywhere else:
Route::post('/test', 'BusinessController#store');
Route::post('/business', 'BusinessController#store');
The calls are exactly the same, they go to the same location but the /business has a redirect.
I've tried clearing the route cache. There's no further information in my logs. I've seen
When using routes, you need to make sure the name does not overlap with the content/structure of your public folder. If there is an overlap, the .htaccess file will just try to access the file in stead. Because the file is a folder, it tries to load it as an ftp page(301), but can't because it is disabled for security reasons(403).
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 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'm developing a project in Laravel 4.x. I'm currently using File::exists() function on the routes.php as an error trap, the code looks like this:
Route::get('/', function() {
if(File::exists("settings/config.xml") {
// do something with the config.
// then go to the site.
}
else {
// cannot proceed anymore.
}
});
I'm developing my project on a WAMP Server. Everything is fine and it returns true until I served it (php artisan serve --port=8080). It now cannot find the file I was looking for! I found an alternative for it to work -virtual hosting, but what I need is the method to check the file exists when it is served.
I've tried to type on the URL address bar the exact path, and it can find the file (the browser downloaded it, in fact): localhost:8080/settings/config.xml
Is there something wrong with my code? Thanks for helping.
EDITED:
When I said everything is fine until I served it, I am referring on running my project through this URL: localhost/project/public
Maybe add slash root to the path.
like this: File::exists("/settings/config.xml")
I'm too newbie to Laravel...I have written this route to echo "Hello World", but It errors NotFoundHttpException
This is my routes.php (no other code is in the file but the following):
Route::get('/', function(){
return "HELLO WORLD";
});
I have also enable mode_rewrite, and also set AlloOverride to 'all' in apache module.
This is also the URL is use to access the page:
http://localhost/laravel/public/mostafa
Do:
php artisan serve
Use that URL to visit your website.
You will see that you get some output like:
Laravel development server started on http://localhost:8000
When you have no clue what Artisan is take a look at this;
http://laravel.com/docs/artisan
Navigate into your project directory with your command prompt and run there the serve command from above.
Example:
Sometimes the default .htaccess file located in public folder doesn't work in apache. Try altering the .htacess as mentioned here. Alternatively renaming your laravel project folder would work especially in XAMPP.
Some other frameworks treat route definitions as relative to the project web root so a path defined as /foo/bar will match http://example.com/additional/levels/laravel/public/foo/bar and will work without changes even if you move the project tree somewhere else in your public web hierarchy. Laravel, however, considers routes as absolute paths so /foo/bar will only match http://example.com/foo/bar.
The simplest solution is probably to move your code into a separate virtual host and point its document root to laravel/public/. (In this case it seems that's actually the intended set-up.)
(I suppose there's a way to make the framework assume an implicit prefix but I've only been using Laravel for 10 minutes.)