laravel localhost and server work different with htaccess and public folder - laravel

After removing .htaccess from public to main, and renaming server.php to index.php all Asset links and links from the css background-image are wrong.
Is there a way to either have the same problem on localhost (the /public in the url) or is there an other easy fix? Cause right now if I fix my code on my online server, it doesn't work locally anymore and vise versa.

External CSS, Images and JS
Example Here,
Your URL Like:
For CSS
<link rel="stylesheet" type="text/css" href="{{url('/public/file_name.css')}}">
For JS
<script type="text/javascript" src="{{url('/public/file_name.js')}}">
After domain name, you must use public and then your CSS, images, and js path.

Related

why I need public word when i live my Laravel project

hello Laravel developers!
I am stuck with Laravel assets URLs.
<link href="/css/app.css" rel="stylesheet">
this link works fine on localhost.
But why i need to add "public" when i upload it to server like
<link href="/public/css/app.css" rel="stylesheet">
I moved app/public/index.php to app/index.php and make changes in server.php and index.php accordingly. Rest is the working fine. issue is only with assets urls.
Similarly, the class
.edu-home-hero-area {
background: url(/assets/images/curve.webp) !important;
}
works fine on localhost but when i upload it, it does not work i need to change it to
.edu-home-hero-area {
background: url(/public/assets/images/curve.webp) !important;
}
please have a look
https://pdaofficial.com/
any help would be appreciated
I'm not sure if i understand your question completely but you should not be moving public folder files some where else. why not reference your css or js assets using asset function. It will directly point to public folder and look for build.css inside css folder.
<link type="text/css" rel="stylesheet" href="{{ asset('css/build.css') }}">

<link rel the bootstrap-4 Source files?

I've been developing a site with bootstrap 4 and linking externally to:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
However, I need to load the site locally as the network connection isn't stable. So I downloaded the full stack bootstrap-4.0.0 Source file and added it to my WebServer directory thinking all I need to do is change the link to to point to bootstrap.min.css, like this:
<link rel='stylesheet' href="http://localhost/webfiles/wp-content/themes/Cussons/bootstrap-4.0.0/dist/style.css?ver=4.9.4">
The site works, but I'm getting a 404 not found for style.css?ver=4.9.4
All permissions at set to allow full access and I cleared caches and all of the links href's appear correct, but I cant seem to get my head around why the site wont pick up the color changes I've added to files like /assests/scss/_navbar.ccss
If anyone can see whats wrong, I'll be very grateful :)
Just download the precompiled files here, place them in an accessible folder and then link them like :
<link rel="stylesheet" href="relative_path_to_css_parent_folder/css/bootstrap.min.css">
same for the js at the bottom of the body :
<script src="relative_path_to_js_parent_folder/js/bootstrap.min.js">
or
<script src="relative_path_to_js_parent_folder/js/bootstrap.bundle.min.js">
Take a look at this : How do I link to my css stylesheet for local file?
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="UI.css"> <!-- made up name-->
<script src="jquery.js"></script><!-- made up name-->
<script src="jquery.ui.js"></script><!-- made up name-->
<script src="script.js"></script>
But what if the js files are all in the projects/js/ folder? Point
your page to this location:
Assuming our HTML is in the blackjack folder, which is a sibling
folder to 'projects/js', then your script tags will look something
like this:
<script src="../js/script.js"></script>
Notice the ../? This references the parent folder of the one the
document is in. We go up one level to where the js folder is.

how to access website stored on xammp via static public ip

I have designed a website. Almost all settings are done such as port forwarding in router etc. The website is also accessed on any computer through internet using static public ip but displays text only without any css effects, images etc.
If the CSS styles, images, JS files, etc. are not displayed outside the localhost (from your IP address), it must be because when you specify the URL or location of those files, you give an absolute URL which works just for localhost.
For example, if you have
htdocs/
index.html
css/
stylesheet.css
img/
logo.jpeg
slider-1.png
slider-2.png
slider-3.png
This will work just in localhost (the computer where xampp is installed):
<link rel="stylesheet" href="http://localhost/css/stylesheet.css">
<img src="http://localhost/img/logo.jpeg">
ETC.
If you want it to work also outside your computer you should use relative paths:
<link rel="stylesheet" href="/css/stylesheet.css">
<img src="/img/logo.jpeg">
ETC.
This is because the HTML code is executed in the client side (in the person who visits your page's computer) so they can't access your files through localhost...
I hope this helps you, I was going to ask you which type of URLs do you use through the comments before answering but I can't add any comments because of my reputation :v

URL rewrite issue not loading .css

I'm porting an old site to a new template and am having problems with the Windows 2008 rewrite module. The link I'm trying to rewrite looks like this:
http://ltweb2008.serveronline.net/product.php?pID=75
and brings up the page just fine. Then I apply the new URL and it loads the proper content, but doesn't load the template's style.css file anymore.
http://ltweb2008.serveronline.net/product/75/any-text-here
The problem seems to be that the company who made the template (canvas) put the main .css file in the root directory, but loaded all the rest in /css. Now I can't get the main .css file to load using the rewrite and when I move it down to /css it only displays a blank page, though when I check out the page source it's all there.
With this the page shows but is not using style.css (with rewrite):
<link rel="stylesheet" href="style.css" type="text/css" />
With any of these the page is completely blank (with rewrite):
<link rel="stylesheet" href="/style.css" type="text/css" /> OR
<link rel="stylesheet" href="/css/style.css" type="text/css" /> OR
<link rel="stylesheet" href="http://ltweb2008.serveronline.net/style.css" type="text/css" />
I'm using this for the Pattern:
^product/([0-9]+)/([^/]+)$
And the Rewrite URL:
/product.php?pID={R:1}
Does anyone know what I'm missing?
one solution is that use absolute path (ex /css, or /js rather than just css/, /js but this is not looks a reliable solution since we've to change it on all files,
This is because your relative URIs have their base changed. Originally, the base is / when the page is /product.php?id=75, and the browser properly fills in relative links with the / base. But when the browser goes to a page like /product/75/any-text-here the base suddenly becomes /product/ and it tries to append that in front of all relative URLs and thus none of them load.
You can either make your links absolute, or change the URI base in the header of your pages (inbetween the <head> </head> tags):
<base href="/">
Maybe you need one thing, maybe both, I didn't test, but this solved it for me:
1.) ADD THIS in page_load :
Page.Header.DataBind() ' Needed because we have <%# %> codeblocks in the HEADER (seems header only causing this) WITH the AjaxControlToolkit running on the page. That's what broke it until we put in this and put in the pound instead of = sign in the html.
2.) Add this in ASPX:
<%# MasterType VirtualPath="~/dir1/dir2whateverdir/MasterPage.master" %>

Including page layout to Laravel project

I was supplied with a custom layout for the login page of my Laravel project.
When I opened login.html file, which represents the layout for that specific page I saw such links
<!-- Base Css Files -->
<link href="assets/libs/jqueryui/ui-lightness/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
<link href="assets/libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="assets/libs/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
...
So I figured that I only need to copy the assets folder, which came with the template (there are all needed bootstraps, jqueries and whatnot) to my projects app\resources\assets directory
Now, when I copied the code from login.html into my login.blade.php view and copied the templates' assets folder to app\resources\assets it doesnt work. It only displays naked html code when I open the page.
What am I doing wrong in linking the assets folder?
The resources folder is (like the name says) for the resources.
If you don't want/need to build/compile/min your scripts, then just put them in the public folder, so you can access them from your template.
In your case
public/assets/libs...
In order to access assets, you have two ways to approach it. Either using Elixir/gulp or to use direct access.
Gulp is a node.js application that reads your assets files, whether JS, CSS, Coffee, etc...and combine them in single files. Gulp reads the files defined in the gulpfile.js, and you can access the output files in your blade file using elixir().
You can read more about Elixir here.
In your specific case, you can just place the files under the public/ directory. So Laravel treats public as the root directory, and if you want to read the file assets/css/foo.css just place the file in public/assets/css/foo.css

Resources