Laravel 5.1 Route Object not found - php

Please help me, I'm working on a Laravel using the latest version of xampp & do not know what the cause of my problem is.
This route is working fine:
Route::get('/', function () {
return 'aa';
});
This route gives an error "Object not found!":
Route::get('about', function () {
return 'aaa';
});
httpd.vhosts:
<VirtualHost test.loc:80>
DocumentRoot "C:/xampp/apps/test.loc/public"
ServerName test.loc
<Directory "C:/xampp/apps/test.loc/public">
#AllowOverride All - when I use this, I get a "Access forbidden!" for all routes
Require all granted - this works for the main route, other routes give "errors".
</Directory>
/public/.htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I faced exactly the same problem, but finally this worked for me.
.....
<Directory "C:/xampp/apps/test.loc/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>

Add this to your httpd.vhosts file
<VirtualHost test.loc:80>
ServerName test.loc
DocumentRoot "C:/xampp/apps/test.loc/public"
<Directory "C:/xampp/apps/test.loc/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

Have you tried adding a slash before the name?
like this:
Route::get('/about', function () {
return 'aaa';
});

Related

Laravel 5.6 deployed application routes give 404 error

I have deployed an application to an apache server and it works fine, well only the homepage. As soon as I try to go to a route I get the Not found error in my request log I see GET /users 404
My virtual host file:
<VirtualHost *:80>
SetEnv ENVPHP acc
ServerName someurlblabla.com
DocumentRoot "/var/www/html/projectname/public"
<Directory "/var/www/html/projectname/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
The .htaccess file is just the default laravel one with apache being able to access and read it.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I'm a bit lost since I don't get any errors in my log and I have no idea what is going on.
what's about this:
<VirtualHost *:80>
SetEnv ENVPHP acc
ServerName someurlblabla.com
DocumentRoot "/var/www/html/projectname/public"
<Directory "/var/www/html/projectname">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
Probably you don't wanna hear this, but switching to Nginx will solve a lot of these problems , and your site will run faster. That's why Laravel Valet uses Nginx.

apache rewrite rule not working as expected

Below is my .htaccess code:
<VirtualHost *:80>
ServerName api.xxxx.com
DocumentRoot /dianxiaoer/html/two-twenty
<Directory /dianxiaoer/html/two-twenty>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
RewriteRule /notify/alipay /mobile/index.php?act=notify&op=alipay
#Options Indexes FollowSymLinks MultiViews
Options FollowSymLinks
AllowOverride None
Require all granted
Order allow,deny
allow from all
</Directory>
</VirtualHost>
URL rewriting rule
api.xxxx.com/notify/alipay to api.xxxx.com/mobile/index.php?act=notify&op=alipay
is not working correctly. Can anyone please explain what am I doing wrong here? Thanks.
This line, RewriteRule . index.php will override anything that comes after it.
If you put that one at the end then it should sort out your issue.
Try swapping line 8 and 9 like this:
<VirtualHost *:80>
ServerName api.xxxx.com
DocumentRoot /dianxiaoer/html/two-twenty
<Directory /dianxiaoer/html/two-twenty>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /notify/alipay /mobile/index.php?act=notify&op=alipay [L]
RewriteRule . index.php
#Options Indexes FollowSymLinks MultiViews
Options FollowSymLinks
AllowOverride None
Require all granted
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Hopefully that solves your issue.

Access api's written in laravel 5.2 without using index.php file (Ubuntu 14.04 in Azure)

I am trying to access api's written in laravel though postman.
By using the below format link i am able to access the api's
http://example.cloudapp.net/suven/index.php/api/register
But how to access without index.php name in the url
I have 2 laravel projects created in /home/azureuser
Below is my /etc/apache2/sites-enabled/api.conf file
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName example.cloudapp.net
Alias /suven /home/azureuser/webservices/public
<Directory /home/azureuser/webservices/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Alias /quiz /home/azureuser/quizapp/public
<Directory /home/azureuser/quizapp/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
SetEnv APPLICATION_ENV dev
LogLevel warn
</VirtualHost>
Below is my .htaccess file in /webservices/public directory
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
#RewriteBase /webservices/public
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Below is my routes.php file
Route::get('/', function ()
{
return view('errors/503');
});
Route::group(array('prefix' => 'api/'), function()
{
Route::post('/register','UserAuthController#register');
Route::post('/login','UserAuthController#login');
});
Route::group(array('middleware' => 'appuser_auth','prefix' => 'api/'), function()
{
Route::post('/changepassword','UserAuthController#changePassword');
});

Apache looks for index.php files in Laravel 5

I am a begginer in Laravel and I am having troubles with Apache 2.2.15 on CentOS 6.5 and Laravel 5. I have searched for this error and I found some solutions for .htaccess and for httpd.conf but none of them are working and i get this error when trying to access "public/auth/register" or "public/auth/login" and even "/home":
Not Found
The requested URL /index.php was not found on this server.
Here is my .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
And here is my httpd.conf
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
The only page that works is the public/index.php
You have to point apache to the public folder:
<VirtualHost *:80>
DocumentRoot /var/www/html/public
<Directory "/var/www/html/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Serving laravel over HTTPs using Angular-UI

I am trying to serve Laravel 4 routes using Angular-UI over HTTPs. Without HTTPs it works but over the same it brings a 404 error.
Thanks for any assistance.
htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Route:
Route::get('index', array('as'=>'index','uses'=>'PagesController#getIndex'));
Angular-UI
state('home', {
url: '/home',
templateUrl: 'index'
})
I have found a solution to it, I hope this helps someone. On linux do the following:
sudo leafpad etc/apache2/sites-available/default-ssl
Then on that file edit the following line AllowOverride None in
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
To:
AllowOverride all
Thank you all.

Categories