wrong url to css files in spring and apache tiles - spring

I'm creating REST application based on spring and apache tiles. I've added .css file and on main page it work everything. I mean when I'm on domain.com/ but when I'll go to domain.com/something/ the url is the same and it's wrong. I would have to add ../ at the start of .css file path
How can I create (by auto) correct file path on every subpage ?

Use absolute paths rather than relative paths:
href="/css/someFile.css"
rather than
href="css/someFile.css"
You must also make sure that the web app's context path is always prepended, so the path should in fact be
href="${pageContext.request.contextPath}/css/someFile.css"
or, if you use the JSTL:
href="<c:url value='/css/someFile.css'/>"

Related

How can I change the directory a relative path points to in apache?

I have a website running on an apache2 server and serving out of a user directory. The URL looks like this: http://example.com/~user1
This serves up files on my server located at /home/user1. The problem that I am facing is that a lot of the asset URLs throughout the site are put into the HTML as relative paths like this: <img src="/images/example.png" alt="" />
This is attempting to load the image from http://example.com/images/example.png, but I actually want it to serve from http://example.com/~user1/images/example.png.
How can I accomplish this?
/images/example.png
This is a root-relative, not a relative URL-path.
This is attempting to load the image from http://example.com/images/example.png, but I actually want it to serve from http://example.com/~user1/images/example.png.
This is a client-side/browser URL resolution issue. There are no "switches" on the server that can be applied to change this behaviour, without changing the actual URLs.
This is an inherent problem with using Apache per-user web directories.
Your options are:
Don't use Apache per-user web directories. ie. Remove /~<user1>/ from the URL.
Or,
Use relative URL-paths to your assets. eg. images/example.png (no slash prefix). So the browser correctly resolves this as /~user1/images/example.png instead (when accessed from the document root at least). But this creates additional problems if you are rewriting the URL of your pages at different path depths or using common templates in your pages etc.

How to show images in thymeleaf that are not in static folder in src

I'm uploading images to a folder productImages which is not in the src folder of spring boot project. I'm storing the paths of each image. How can i use th:src=#{product.image} to display the image where product.image is the path from database(e.g productImages/photo.jpg). My problem is getting the location to the folder.
As I understand it, you wish to specify server-relative links in Thymeleaf. (as opposed to context-relative). Basically, when you want to specify a resource outside of the application context, but relative to the server, you use the tilde notation. So, instead of:
th:src="#{/product.image}"
you should use:
th:src="#{~/product.image}"
You will find very nice clear & concrete examples with explanation at:
https://www.thymeleaf.org/doc/articles/standardurlsyntax.html.
Hope this helps! :)

CodeIgniter: How to load css file that is WITHIN application folder

It appears that this question is asked often and answered the same way: store the css files outside of the application directory and then use base_url() . "path/to/file".
However, I want to keep my css files and js files inside my application/views/ directory, because the views directory is effectively the html space, and css and js belong to that space (in my opinion).
Below is the structure that I wish for:
root
- application
-- views
--- assets
---- css
---- js
- system
When I attempt to load css files from within this directory structure, I get a NetworkError: 403 Forbidden, which makes sense because of CI's framework protocol.
But I am guessing that there is a way.
Publicly reachable files like CSSes images and JS files need to be in public directory next to index.php file. So hierarchy would be:
root
- application
- system
- assets
-- css
-- js
You can aproach to those files with hard coded
Link
or using (loaded) url helper with it's function base_url() or site_url(). Don't forget to fill correct URL into application config file.
Link
Docs.
Hey i'm going to politely push back on this idea :-)
Your application and system folders should be ABOVE the root, so they are not publicly accessible. (Unless this is a really simple application and you are not doing any database interaction, etc). They should not be considered part of the HTML or public space because you do not want the public accessing them. Set the path for them once in the main index.php file and its done.
Also i suggest renaming your system and application folders, like "system302". Over the long term it makes versioning and upgrading (and reverting if needed) much easier.

Images not loaded from js file

I have a javascript plugin that loads some images from the js file itself. I included the js file like that echo '<script src="'.base_url()."js/$js_file.js".'"></script>, the js file loaded correctly but the images not loaded. When i checked the images path from the firebug i found the path relative to the controller http://localhost/mysite/controller/images/nicEditorIcons.gif which the images is the folder that holds my images(its in the root folder).
What is the problem here? and how to let codeigniter load resources correctly?
you should add an slash "/" before any path which is calling a resource to be relative to the root site, first locale your javascript plugin which I think there is where you add the paths to the images that I think looks like images/nicEditorIcons.gif change that to look like /images/nicEditorIcons.gif to be relative to your root path I mean to http://localhost/mysite, so that way it will look like http://localhost/mysite/images/nickEditorIcons.gif instead of the URL you have shown, hope it helps.

call .htc file from all html pages withot adding url domain

In that same CSS rule, add the following style line:
behavior: url(path/to/PIE.htc);
Of course you will need to adjust the path to match where you uploaded PIE.htc in step 2. Note: this path is relative to the HTML file being viewed, not the CSS file it is called from.
but if my url is domain.com/foo/foo.html PIE.htc is not loaded any more if i use
behavior: url(PIE.htc);
PIE.htc is located in root. Can i somehow always call .htc file from root?
URIs starting with a / are relative to the site root.
The behavior property requires the URI to the HTC file to be specified using the URL() syntax. Multiple HTC files can be referenced with a space-delimited list.
So suppose your csshover.htc file is in csshover directory and you can reference multiple HTC file or specially same file but from different directories
like behavior: URL('csshover/csshover.htc') URL('../csshover/csshover.htc') URL('../../csshover/csshover.htc') URL('../../../csshover/csshover.htc'); and so on.

Resources