404 error in Laravel 6 , changing .htaccess - php

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.

Related

Unable to browse to anything other than the main URL on a new Laravel Apache2 setup. ERROR: The requested URL was not found on this server

I've set up a new Laravel site with an Apache2 webserver and have mimicked the setup of a similar working site, on the same server, but every time i browse to a URL which is example.com/anything it gives me a 404 page not found error. The main site url works, but no pages are accessible.
Eg:
example.com {{ This works fine }}
example.com/home {{ Errors with page cannot be found }}
example.com/anything-i-put-here {{ Errors with page cannot be found }}
The site works fine on other servers and locally, so im certain its not the Laravel site itself thats broken. Another laravel site on the same server with basically identical setup (as far as i can see) works fine, so I know the server itself is set up correctly and is serving other sites.
I'm fairly new to apache2 virtual server setup, so im pretty sure i've just not configured this correctly. I've been trawling through the internet and have read so so many posts reccomending people to set up the apache2.conf and the .htaccess files basically exactly the same as i have them, so im at a bit of a loss. Has anyone got any suggestions?
apache config file (symlinked in sites-enabled):
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect 301 / https://example.com/
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/example.com/public_html/public
ServerName example.com
<Directory /var/www/example.com/public_html/public>
Options -Indexes +FollowSymlinks +MultiViews
AllowOverride All
Require all granted
# SSLRequireSSL
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/www/example.com/fpm/php7.2-example.sock|fcgi://localhost/"
</FilesMatch>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile path/to/key.pem
SSLCertificateKeyFile path/to/key.pem
</VirtualHost>
.htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# 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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and yes, modrewrite is enabled
Use the following code in your .htaccess after RewriteEngine On
RewriteBase /
So your .htaccess should look like the following:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /
# 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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

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.3 Route NotFoundHttpException

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>

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