laravel 5.6 not redirecting properly - php

I am setting laravel 5.6 in a subfolder but it is giving error the page is not redirecting properly. I have tried everything with the htaceess. I have setup the htacess at the root folder as well as the public folder but it is not working
My root htaccess is
<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>
and here is my htacess for public folder
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /charity-frontmode/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
Please help! Thanks in advance

Try the following
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

Related

Front page loads but other return 500 Internal Server Error on shared hosting

I deployed my laravel 4.2 website on a shared hosting with ftp but the routes are not working. The fronp page loads fine but when i try to go to another page it returns "500 Internal Server Error". : It's reading the .htaccess file but i don't know if its correct. It's auto genereated from laravel. I uploaded it bellow. I also tried giving write permission to storage and bootstrap folders but it still doesn't work.
Edit: I noticed something interesting. if I go to www.example.com/test is returns the 500 internal error but if i go to www.example.com/index.php/test , now it loads correctly. Any idea how to fix it?
Edit2: IT WORKS. I just had to exclude index.php from the url with:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
.htaccess file
<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>
updated .htaccess file that fixed the problem
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

wordpress install on same domain with laravel on apache ubuntu

I have installed wordpress with laravel 5.3 in news directory inside /var/www/html/public/news/ folder.
mydomain.com/news will redirect to mydomain.com/public/news/ as an 404 error page by wordpress.
Although mydomain.com/news/ some normally.
So, what is the cause behind and how to resolve it?
My .htaccess files are as follows:
root directory /var/www/html/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
/var/www/html/public/ directory
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond $1 !^(news)
# 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>
/var/www/html/public/news/ directory
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /news/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /news/index.php [L]
</IfModule>
# END WordPress

Laravel home url not working?

When I open the home url: http://localhost/laravel/public/ it redirects me to http://localhost/public and gives me
Error 404
The .htaccess file is the default one and it used to work perfectly, I don't know what went wrong?
Here is the .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]
Try adding a RewriteBase to the htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /laravel/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Try using the following .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Laravel skip directory from framework

I am facing a problem, the mapping of my site looks like this:
- app
- bootstrap
- public_html
- archives
- css
- js
index.php
- vendor
composer.json
etc...
My .htaccess is located in public_html. I want to skip the directory public_html/archives from the whole framework. How would I do that? I want the route mysite.com/archives to be accessible outside Laravel.
Edit:
Here is my htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_URI} "/public/archives/" <--- ADDED!
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
As others have noted, Laravel won't process any files or directories that exist because of the following rules:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
First, take this rule out of your .htaccess file:
RewriteCond %{REQUEST_URI} "/public/archives/"
Then, after the RewriteEngine On line, you need to add this rule:
RewriteRule ^archives/?$ - [PT]
So your .htaccess file will look like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteRule ^archives/?$ - [PT]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Alternatively, you can just add the following line before RewriteCond %{REQUEST_FILENAME} !-d:
RewriteCond %{REQUEST_URI} !^/archives/?.*$

Laravel not detecting files from public folder

hello people below is code of .htaccess inside public folder...
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteRule ^ index.php [L]
# Redirect Trailing Slashes...
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
</IfModule>
As though i have some images inside public folder...'not found error message is displayed' ...anyways to fix this???
<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 changing it to this make sure this .htaccess is inside of your public folder.
inside app i have this other .htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
and laravel works just fine!
Try this code. It will work prefect in Shared Server or other Server.
For Fix this issue. i did some steps :
copy all files from Public Folder to root Folder.
change path in index.php means replace it '../' to "/".
update .htaccess file with this code.
I have also added a code for Hide env file. if you not add that code then anyone can see your env 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]
#RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.woff|\.woff2|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_URI} !(\.svg|\.woff|\.woff2|\.ttf|\.css|\.js|\.png|\.jpg|\.gif|\.pdf|\.jpeg|\.docx|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images|admin|userimage|ckedit_images|video|thumbnail|fonts|amenities-pic|img|propert|property_video|vendor|photos|files|doc|flags|1x1|4x3)/(.*)$ public/$1/$2 [L,NC]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
#hide a Specifuc Laravel .env File
<Files .env>
order allow,deny
Deny from all
</Files>

Categories