Laravel 5.1 show indexes for existing folders - php

I have a problem with Laravel 5.1 routing, If I try to make a route with the same name that a folder in the /public folder apache shows me the index of the folder (I have forbidden indexes so it shows a Forbidden message) I don't know if it's impossible to make it work, I have obviously changed the name of the assets folder with the conflictive name in public directory, but it would be awesome if I could name it as I want.
If I wans unclear (because my bad english) the short explanation is the following:
I have a "game" folder in the /public folder of Laravel 5.1
I want to have a route named /game (example.com/game)
When I acces to /game apache shows me the index of the folder, instead of redirect me to index.php as rewrite rules do.
Thanks in advice

In your htaccess file there is something like this: if there is no file or directory for the URL then give the URL to laravel.
Just remove the directory check and it should work fine. (Please post your htaccess file so I can tell you what line you have to remove)

Related

Laravel specific folders act as root

I came across problem in laravel, cant find a solution, maybe you could help me out.
I have many folders with HTML documents that are linked (same folder as HTML) with css, some of css are inside assets, includes, root folder.
I can access these html files by going https://website.com/live/1/index.html but the problem is that laravel sees css and other files in website root folder https://website.com/assets/app.css instead of https://website.com/live/1/assets/app.css
I think I could find a solution in htaccess by typing RedirectMatch 301 ^/(assets/.+)$ /live/1/$1 but then it means, that I have to create and edit htaccess everytime for a new folder.
Maybe someone has any solution to this problem ?
You can change your default asset URL with your .env file and add this
ASSET_URL=https://website.com/live/1
it would change your asset() method behavior

Error 404 after migrating laravel 8 to a shared host

Hello everyone i am new to laravel and i hope someone can help me about my problem. I created a laravel project. After that I import it to cpanel using softaculous. Then, I made some changes base on what i research in the net to avoid showing important file like .env . I created a folder relative to public_html, let say the folder name is 'tamangbilang' where i put almost all of my code except the index.php. Inside my public_html folder, I have another folder named as 'tamangbilang' where my index.php resides. I have followed this instruction https://dev.to/pushpak1300/deploying-laravel7-app-on-shared-hosting-hostinger-31cj the only difference is that I put another folder inside public_html.I also did some changes on the index.php code
require __DIR__.'/../../tamangbilang/vendor/autoload.php';
$app = require_once __DIR__.'/../../tamangbilang/bootstrap/app.php';
Everything is working fine on my login page(my first page) but when I try to login, an error occur.
The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
It seems like the connection between routes was lost. I did further testing and I notice that the code is working well only if there is an index.php, before the route in the url. example
http://my-sample-domain.org/tamangbilang/index.php/login
P.S. I don't have access for ssh.
go to bootstrap folder & open cache folder then delete config. after that please check your routes this error basically arises due to routes not found for that go to your project installed on local and write php artisan route: list check if the route is present or not.

move laravel to live web

Hi I have my website which its my resume and now I want to show the project that I have done one of my project is laravel and I move it to: public_html/laravel
and also move my DB to there but I get this error:
403 Forbidden
You don't have permission to access /laravel/ on this server.
I don't understand is it because of I didn't put files on main public_html and move it to folder or other stuff I also changes(i don't know if its right) change config/database.php mysql part to database configuration but I keep getting this error
Laravel server files from the public/ directory. So try a URL like this instead:
http://example.com/laravel/public
If that works, you'll need to move some files around a bit. This should help with moving things around:
How to change public folder to public_html in laravel 5
If you use shared hosting then please do not uplaod whole laravel application to the publitc_html folder. You have to upload your all application at global document root for your domain like home/yourdomainand you have to rename existing public_html folder to any name and rename laravel public folder to public_html and try again. See the image below:

How to stop Laravel directory errors

Is there a way in laravel to make directory accesable without Laravel having to get involved?
I recently ported a Wordpress website for my brother into Laravel (which I am new to) and all of the image paths are hard coded in the body of the blog article.
The issue I am having is that the url it need to read the image at is:
http://www.theunlikelytraveller.co.uk/wp-content/uploads/2015/11/DSC_0728.jpg
but laravel doesn't like that.
Here's the article: http://www.theunlikelytraveller.co.uk/posts/a-return-to-the-beautiful-balkans
Can anyone help?
If you want to force Laravel to ignore wp-content directory, for example, you can edit .htaccess file inside a public directory:
RewriteRule ^wp-content - [L,NC]
This line should be added before other rules.

Affect on security of Laravel 5 when change folder structure to remove public folder

I'm new in Laravel 5.
I found this Laravel 5 - Remove public from URL on Stack Overflow to remove public folder from my Laravel 5 App. Only I have a question about the security.
When I am removing public from URL, then I have to change the basic folder structure of Laravel 5. Yes, it's working fine without the public from the URL.
But what's about the security of Laravel, because I am changing the default folder structure? Is it secure to use?
You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.
The point of having sub directory for www host root instead of project root is that you're not leaking any of your project files through your web server.
Even though all the PHP files have the file suffix .php, malicious user can access your $LARAVEL_PATH/storagedirectory and its subdirectory contents, read your composer.json or package.json to find vulnerable dependencies or read .env file etc.
If you're running on shared hosting and you have mandatory public_html, try installing Laravel outside of that public_html directory and either removing public_html (if empty) and replace it with symlink to $LARAVEL_PATH/public OR if you want the Laravel instance to be subdirectory ofpublic_html, do the same but create symlink from$LARAVEL_PATH/publictopublic_html/$PROJECT_SUBDIR`.
That public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition. :)
you this link you provided is not about changing the actual file structure of the framework, this example uses mod_rewrite to rewrite the url of your application. In other words you are telling your server that you would like to point to that directory without the full path is visible to the end user.
Also take a look on the below answers of the link you've provided.
Rename the server.php in the your Laravel root folder to index.php and
copy the .htaccess file from /public directory to your Laravel root
folder. -- Thats it !! :)

Categories