Laravel 5.3 Route NotFoundHttpException - php

I have deployed my Laravel 5.3 application on an AWS server running Ubuntu and php 7. i have created an alias in the /etc/apache2/sites-available/000-default.conf file as below:
Alias /myapp.dev /var/www/html/myapp/public/
<Directory "/var/www/html/myapp/public/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /var/www/html/myapp/public/
</Directory>
But when i try to access with the alias as 52.xxx.xxx.xx/myapp.dev i get the following error:
How ever when i access it with full url to the public/ directory it works fine
eg. 52.xxx.xxx.xx/myapp.dev/public/login
I have enabled a2enmod and my .htaccess file in /public directory is as below
<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}]
any ideas as to why i am getting the Route NotFoundHttpException in my aws server and not to forget to mention that in my local windows machine running php 5.6 also is running fine with a vhost. Your ideas are very much appreciated. Thanks in advance

Try this .htaccess. Hope it will help.
<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>

Related

404 error in Laravel 6 , changing .htaccess

I'm totally new in deploying project on server. I am facing some issues. Could not solve it.
My project path is
/home/office_user/htdocs/projects/admin
inside
/home/office_user/htdocs/furusato -> there are some other project running.
inside /etc/apache2/sites-available/000-default.conf
DocumentRoot /home/office_user/htdocs
ErrorLog /home/office_user/logs/error.log
CustomLog /home/office_user/logs/access.log combined
<Directory /home/office_user/htdocs>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
and /home/office_user/htdocs/furusatoadmin/public/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
DirectoryIndex index.php
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
# RewriteRule ^ %1 [L,R=301] ココはコメントにする
# 以下は追記部分 ----------------------
RewriteRule ^(.*)/$ /admin/$1 [L,R=301]
RewriteBase /admin
# ココまで ----------------------------
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
when i tried to access
ip/admin/public/index.php
404 error
and
If I try to access ip/admin/
it is showing
Forbidden
You don't have permission to access this resource.
Please help me find out the solution.
I tried a lot of different things but nothing is working.

Apache2.4 & Laravel 5.4 with alias in a subfolder doesn't work without /index.php

I've created an alias on apache server conf file (/etc/apache2/mods-enabled/alias.conf) to target the public folder.
Alias /laravel/ "/home/user/dev/web/laravel/public/"
<Directory "/home/user/dev/web/laravel/public/">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Require all granted
</Directory>
Also, I wrote the following .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/laravel/(.*) /laravel/index.php/$1 [L]
</IfModule>
Now, when I'm visitng the http://IP/laravel the index.php is loaded as expected. But if I'm gonna make a call to a GET Route like http://IP/laravel/load_examples I'm getting back a NOT FOUND error.
Instead, if I visit the http://IP/laravel/index.php/load_examples, route loaded as expected.
It seems to me that something's going wrong with the .htaccess and rewrite rules.
I tried everything I found on the SO and other places but couldn't find any solution so far.
Any idea?
In the alias before the the code block shown try adding:
DocumentRoot /home/user/dev/web/laravel/public/
And then try this for your .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]
</IfModule>

laravel 5.4 removing public form url not working properly

I have renamed server.php file to index.php and added .htaccess code as follows
<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>
url is working fine now, it is working without url, but
asset()
public_path()
function are not working properly.
css, js , images are not called properly.
{{ asset('assets/css/custom.css') }}
Above code to all custom.css is not working, it was working properly before.
If I add public than it work properly, but that is not correct way.
{{ asset('public/assets/css/custom.css') }}
Let me know how can I add public globally to these function.
I also tried to remove url using this reference but it doesn't work.
How can I remove “public/index.php” in the url generated laravel?
I do three things to solve this.
I put this htaccess file in my project root folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
And this .htaccess configuration in my public folder, that is, project-folder/public
<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]
</IfModule>
then define my virtual host configuration as
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/path/projectfolder/public"
<Directory "/path/projectfolder/public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require All
</Directory>
</VirtualHost>
This solves the problem for me

laravel 5 https always 404 for any route

I have laravel 5 running ubuntu on aws with apache2. The site and route works with no http.
When hit e.g. https://example.com, only the home page works. The other pages returns 404. e.g. https://example.com/home returns 404
.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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
the 000-default.conf
the ssl.conf
The servername don't have be there for aws to work.
based on this: How can I fix Laravel 5.1 - 404 Not Found?
the ssl conf need to "mirror" 000-default.conf. i.e.
<Directory>
......
</Directory>
This part needs to copy to the apache ssl conf from 000-default.conf

Removing Public from URL but allow 'Publications'

I know this question has been asked a million times, but bear with me here. I use an .htaccess file at the base directory of my local server with:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
This works great, but only one problem. If I put anything with 'public' in the first URL parameter, it gives me a 404.
So if I have www.test.dev/publications, it 404's me because it has 'public' in the name. I've tested thoroughly to make sure it was an HTACCESS issue and it definitely is. If I name the route www.test.dev/publi, it works fine, same with www.test.dev/publi-cations.
Does anyone have any ideas here to allow publications inside the URL with an .htaccess file?
Thanks!
EDIT: Just thought I should let you know that yes this isn't the right way to go about removing public from the URL, but my company refuses to change host and I don't have access to modify the site root.
/public/.htaccess
<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>
To remove the /public/ part of your urls, you don't have to add /public/ to your .htaccess, you need to point your VirtualHost DocumentRoot directly to that folder, this is an example:
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/yourdomain.com/public
<Directory /var/www/yourdomain.com>
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And then just have something like this in your .htaccess:
<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>
Try this in .htaccess, it works with http://blog.dev/publications from my localhost
<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>
Try this rule:
RewriteEngine On
RewriteRule ^((?!public/).*)$ /public/$1 [L,NC]
UPDATE: Suggested /public/.htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /public/
# Redirect Trailing Slashes...
#RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

Categories