Laravel specific folders act as root - php

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

Related

Nested file's URL in PHP

I am working on admin panel to add/edit/delete the posts.
So far I had all php files in root directory but I would like to structure it and put admin's related files in other directory(root/adminFiles) and here comes the issue of accessing adminLogin's URL as I was accessing it by typing domain/adminLogin and after moving admin's related file to different directory I would have to type domain/adminFiles/adminLogin.
I was thinking about renaming adminLogin.php to index.php (I think this is how Wordpress solved it) but then I have more than one index.php and it may be confusing, please advice best solution

Laravel does not find css file : GET http://localhost:8000/cssFile net::ERR_ABORTED

My laravel project does not find any of the css files of any of the pages. It shows up with the error,
GET http://localhost:8000/dashboard.css net::ERR_ABORTED
Did not find too many of the similar questions but tried the some solutions that I have found but obviously those did not help, otherwise I would not be asking again.
I`m using a Ubuntu PC.
Here are everything that I have tried.
Checked file permissions, all the files have all read, write and execution privileges.
Tried restarting the localhost many times.
Tried using the asset() function, <link rel="stylesheet" type="text/css" href="{{asset('dashboard.css')}}">
Tried using absolute path though I have the css files in the same directory as the blade.php files.
None of the above mentioned ways fixed it. Some clue would help me a lot. Thank you.
The CSS files need to be in the public folder, or a subfolder of public, not the view folder where the blade php files are. public is where you want to put any javascript files, css files, images, or whatever, and the root of the public folder becomes the root of your website when it's running.

Laravel URLs not working in subfolder

I've finished my laravel project and played it in a subfolder on my domain.
https://example.com/swap
So the above is the root of my directory and when I go there, I do get the index. But now every link I press, I'm redirected to the root of my domain. So I'm getting:
https://example.com/events/1
Instead of https://example.com/swap/events/1
Am I forced to change all URLs by hand in my files are is there a way my htaccess can always redirect to this 'swap' folder and place everything behind that?
I've tried using groups in my routes, without success.
Use url for all your links which are inside views folder:
For subfolder link use:
Sub-Folder Link
For root folder links use this syntax:
Index
There might arise issues with stylesheet and javascript in 'swap" sub-folder links with a 404 error. To fix that, use:
<script type="text/javascript" src="{{asset('js/app.js')}}">
<link rel="stylesheet" type="text/css" href="{{asset('css/app.css')}}">
You need to direct your VHOST to laravel's public folder. This is done for security purposes. Ideally your laravel install is outside the public folder, thus you would have yourdomain.com contain your laravel install and rename your public folder to swap.
IF you really want the name swap in your routes you could use route prefix with groups.
Open .env File and Change Your App Url to https://example.com/swap/ and use routes as links of whole application
All Url's Will Work fine.
When putting a laravel application in a subfolder. You need to modify your .htaccess for subfolder hosting. And add the following:
RewriteBase /swap
This way, the app knows when you go to route {{ url('/hello-world') }}, it will ultimately go to "/swap/hello-world"

Bypass Symfony framework to display folder content

First of all. I haven't got any knowledge about Symfony. I just have to do a few modifications to an existing site quick and dirty. Now here is the case.
I need to "bypass" the Symfony framework to access static content in a folder e.g. (domain.com/folder).
This folder contains index.html and all the needed images, css, js etc. It also contains sub pages like (domain.com/folder/sub.html, domain.com/folder/sub2.html etc.). These sub pages are accessible thourgh domain.com/folder/index.html.
How can I do this?
SOLVED: (by user3749178)
Put you folder under /web. And a note for anyone else -> you also have to reference the file name.
domain.com/folder/ -> does not work
domain.com/folder/index.php -> works
Put you folder under /web. Everything what is in your /web directory is visible via http.

Best way to organize a website root

I have made a website (WP based) and put every stuff inside the /site folder.
I did that, thinking of creating "custom" systems, and putting each one inside a folder, so for example: /promo would go to something else than the website...
But, I have tried with both .htaccess redirect and PHP location redirect, and when I try to "share" the website, without it's /site folder included, Facebook doesen't detect's the site meta...
Also, is it a problem for google, to use redirect's when accessing the website without the /site WP home folder? I mean, a guy comming from a www.onesite.com would have it's "referer" header as onesite, or mysite?
Thanks
I feel like you're creating your own problems. Just put WordPress in document root and don't bother with rewriting to a subdirectory. WordPress won't delete any custom files or folders when updating.
If you have some custom part that you want to reach through http://www.example.com/promo. Put it in the promo folder under the document root.
If want to reach the custom part through http://promo.example.com, just create new virtual host.

Categories