Loading resources in Laravel Valet without trailing slashes - macos

I have a simple html file (trying to start my way with valet) and in it i have a <link rel="stylesheet" href="./css/main.css">
Thing is, home.test/app doesn't show my styled htm. Chrome's inspector shows it tries to find the resouce file at home.test/css/main.css
While in home.test/app/ it is *not* styled.
Ive been googling a cause/fix for some time and i cant wrap my head around it.
I have tried copying some of Statamic's valet driver configs without much success as a www.conf file.
Also, ive seen some rewriting methods like
rewrite ^/(.*)/$ /$1 permanent;
rewrite ^/?(.*)$ /$1 break;
also without success
I'd like to access home.test/app and have it load all required files and if possible to redirect home.test/app/ to home.test/app removing the trailing slash

The issue is likely to be down to the use of ./ in the href of the link. You're telling the server "go grab me the file from the folder /css/main.css from my current folder location.
Assuming your folder structure is:
/index.php
/css/main.css
/app/index.php
When you're on the home page, you're saying go and retrieve home.test/css/main.css. However, when in the app folder, you're telling the server to go and retrieve home.test/app/css/main.css, rather than home.test/css/main.css.
The quickest solution will be to change the link to <link rel="stylesheet" href="/css/main.css"> (getting rid of the leading .). Otherwise you can use an absolute path.

Related

Hide directory in source code

Actually my question is How is folder path hidden ? Firstly I am using Joomla.
I found a website 4 months ago, so i don't remember name of the website which is Joomla site. They hide their folder path.
Between to head> sth. head(tags). If you look at source code, you can see this part. And then this part include template name.
For example:
<link type="text/css" href="http://www.site.com/templates/template_name/css/style.css" rel="stylesheet"></link>
So we can learn to what the name of the template. But they hide this part. When i looked this part(http://www.site.com/templates/template_name/css), i can see only /style.css.
Do you have any idea?
You need two things to accomplish that.
A (system) plugin, that changes every template related URL to the 'official' format, eg.
$url = str_replace('/templates/template_name/css/', '/style/', $url;
An .htaccess redirect reverting the change.
RewriteRule ^style/(.*)$ templates/template_name/css/$1 [R=301,L]
If you want obscure template names, and a few modules and plugins from HTML source, the easy way is use a CSS and JS compressor like jbetolo or RokBooster.
But keep in mind that you will make a bit more hader to find your template name, but still possible via other ways. Like some images if they are not compressed in HTML.

Magento base url not reflecting value changed in database (missing /)

This is one of those things that on the surface of it seems very simple to resolve, but it's got me beat!
I can see from searching around that quite a few people have had this issue crop up but there seems to be no solution that I can find.
What I've done:
1. Transfered my site from the root folder into a /shop folder.
2. Changed the database entries for secure/unsecure base urls to https://www.dnabaits.com/shop/
3. Cleared out all the Cache and Tmp files.
What's happening:
The whole site is functional but no styles or scripts are being loaded because the paths in the head are missing the trailing / after shop.
So instead of getting this
mydomain.com/shop/skin/........
I'm getting mydomain.com/shopskin/........
An example Url from my page source
<link rel="stylesheet" type="text/css" href="https://www.dnabaits.com/shopskin/frontend/default/dna/css/lightbox.css" media="all" />
In your .htaccess file make sure you have this (with trailing slash):
RewriteBase /shop/
Another possibility is that your Store Configuration Scope for your Store View has a different setting. Change your Configuration Scope in Admin -> System -> Configuration -> Web and make sure your URL settings aren't customized there.

mod_rewrite proxy URL missing images/css

I have the following mod_rewrite using Proxy flag to redirect from one URL folder to another site subdomain as follow:
The .htaccess file placed inside http://www.domain.com/test/ folder:
RewriteEngine on
RewriteRule ^($|/.*) http://subsite.site.com/$1 [L,P]
The problem, images, CSS and links are not showing up properly. Links appear to be pointing back to: http:// www. domin .com/linkname.html
I've tried doing RewriteBase /test/ and / with no luck, and couldn't figure out any other way to do it.
What am I missing in above code to make it work with relative paths at destination URL?
Oh, you want to change internal content?
Mod_rewrite only changes headers, not content and you would definitely need something else like mod_proxy_html. However, rewriting content just to change urls can normally be completely avoided (assuming you have control of your content) by making all paths legitimately relative. In such cases all paths in content should be like: linkname.html or some_path_from_here/linkname.html instead of /linkname.html or some_path_from_here/linkname.html

How to link assets(images,stylesheet etc) in Views for CodeIgniter 2.1?

I am using CodeIgniter Version 2.1 & trying to link assets like images,stylesheets, javascript files etc in my views by using, header.php:
<link href="<?php base_url();?>css/style.css" rel="stylesheet" />
my controller code, calls the view:
<?php
class Main extends CI_Controller{
public function index() {
$this->load->view('header');
}
The view file from which I am trying to load the asset is located
../application/views/header.php.
the css file is loaded:
../application/views/css/style.css
this does not work. I get 404 - Page not found error.then, I tried moving css/style.css outside ../application directory in webroot. To my surpise, having assets in webroot(outsite ../application/views) seems to work nicely.
Now,
My Question is
Is having our assets directly in webroot, outsite ../application directory right approach? If YES/NO, then why?
If having assets directly in webroot is a good idea, than should I move ../application/views directory in webroot as well? How?
PS: I am new to CodeIgniter framework, so unaware of the best practices
If you see this, the section where .htaccess is used to remove index.php from the urls, that has a rewrite condition:
RewriteCond $1 !^(index\.php|images|robots\.txt)
In this line, images is a folder that will be ignored while mod-rewriting. So, you can replace it by assets, put all your directly linking files there, and happily use them.
RewriteCond $1 !^(index\.php|assets|robots\.txt)
EDIT: my bad, hadn't seen the date the question was asked. nevertheless, should be useful for someone.
It is best to put your assets in the webroot folder. When requesting assest from the server (depending on your setup), it will start from the root directory and work it's way down.
http://yoursite.com/application/views/css/mystyles.css
if it's in the root you only need to go from there
http://yoursite.com/css/mystyles.css
Although it might be worth putting them all inside a folder (/assets) to keep them contained, as well as the ability to write a more effective rewrite rule (if you are trying to remove the index.php from the url) to ignore the single folder instead of all the individual folders (/css, /js, etc)
As for the views folder, it's best if you leave it in the application folder as CodeIgniter has a built in loader that automatically checks /application/views for the view file when you use the code $this->load->view('myview')
Although there are way to move the views folder, if you are new to CI it's probably best to leave it there for now.
For linking css you can do something like:
echo link_tag('css/mystyles.css');
Check this for ref: http://codeigniter.com/user_guide/helpers/html_helper.html

Remove part of URL only for certain kind of files with mod_rewrite

I need your help. I have a Joomla site working. I enabled it friendly urls and it works fine. All rewritten URLs are this way
http://mydomain.com/start/article-page-well-rewritten
When I activate Joomla Cache plugin, when I load page first time, it works fine, but afterwards, it doesn't load any css or image file.
Debugging resulting html, I realized cached file has these images and CSS links
mydomain.com/start/images/coolimage.jpg
mydomain.com/start/css/stylesheet.css
Instead of
mydomain.com/images/coolimage.jpg
mydomain.com/css/stylesheet.css
(real routes)
So I think I need a rewrite rule to remove word "start" from url, and then retrieve them and show, but only to image and css files from mydomain.com/start/
Can you help me how to do it? I don't want anything else to be rewritten...
RewriteRule ^start/(images|css)/(.+) /$1/$2 [R]

Resources