nice URL relative link issue - php

I am using nice urls without rewrites (e.g. /my/site/index.php/some/page). I am having trouble with stylesheet links. For example, sheet.css is getting interpreted as /my/site/index.php/some/sheet.css.
How can I get it to link correctly, for any prefix (/my/site/) and any depth suffix (/some/page)?

add a / in front of any resource to point them to the root directory of your site:
<link rel="stylesheet" type="text/css" href="/sheet.css">
You can always setup a CONSTANT in your included config file and add the site path to it
define('HOST_URL', 'http://www.example.org/my/site/');
define('HOST_URL', 'http://www.example.net/my/site2/');
then you can call any file and change the paths whenever you want from 1 single file.
Eg:
<link rel="stylesheet" type="text/css" href="<?php echo HOST_URL; ?>sheet.css" />
<script type="text/javascript" src="<?php echo HOST_URL; ?>script.js"></script>
<img src="" alt="<?php echo HOST_URL; ?>images/image.jpg" border="0" />

Related

bootstrap.min.css Failed to load resource: net::ERR_CONNECTION_REFUSED

I am struggling with linking all my files : css, JavaScript, bootstrap, images etc... On my local server works everything fine. When I upload to my web server I got this error...and I know it is because of the path that I have. It searches everything on my local. and I am using Codeigniter framework, so I have no idea what the path should be when I put it online.
Example :
<link rel="stylesheet" type="text/css" href="<?php echo css_folder_url('reset.css'); ?>" media="screen"/>
<link href="<?php echo base_url() ?>web/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
This is how I need to link in this framework
Maybe I should change something in my host file :
andreaportfolio.local
::1 andreaportfolio.local --> maybe should be .com instead of local
Photo about the error message
here there is how things should work in a small step-to-step guide:
Create a folder called 'assets' in /wamp/www/yourProjectDirectory [In WAMP server];
Edit the config.php in yourProjectDirectory/application/config directory as:
$config['base_url'] = 'http://localhost/yourProjectDirectory/';
<link href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet">
Create the controller as Boots.php;
Create the view file as samplebootstrap.css
<link href="<?php echo base_url('assets/css/bootstrap.css');?>" rel="stylesheet">
Go to the web browser and type:
http://localhost/yourProjectDirectory/index.php/boots/getBoots
Here you can find a dedicated thread on the topic:
https://forum.codeigniter.com/thread-1146.html
Hope this could help,
L.
This error usually means that the specific file was not found. So either the path is wrong or the file is not present where you want it to be. Try to access it by entering source address in your browser to check if it really exists there. Browse the directories on the server to ensure that the path is correct. You may even copy and paste the relative path to be certain it is correct.
There can be a '/' missing as well, for example:
<link href="<?php echo base_url() ?>web/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
could be
<link href="<?php echo base_url() ?>/web/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">

CSS not loading inside sub directory

I am trying to load the css from a sub directory through index.php and have defined a constant AMIN_CSS ="http://localhost/gbl_admin/admin_css".
This being in the same directory loads the css:
<link href="<?php echo ADMIN_PAGE."/style.css"?>" type="text/css" rel="stylesheet">
but this one is in the sub directory:
<link href="<?php echo ADMIN_PAGE."/admin_css/style.css"?>" type="text/css" rel="stylesheet">
//constant decleration
define("SITEURL",'http://'.#$_SERVER['SERVER_NAME']."/");
define("ADMIN_PAGE",SITEURL."gbl_admin");
define("ADMIN_SCRIPTS",SITEURL."gbl_admin/admin_scripts");
define("ADMIN_CSS",SITEURL."gbl_admin/admin_css");
This one doesn't load!! How can i solve this?
The second link which you are referring is perceived as
http://localhost/gbl_admin/admin_css/admin_css/style.css
You can see that admin_css is repeated twice hence it is not able to load the CSS File. Hence the correct url should be as follows :
http://localhost/gbl_admin/admin_css/style.css

http://localhost/ appears before path

In the beginning of the PHP file, I am defining the ROOT as
define('ROOT', dirname(__FILE__));
It works when i use something like
require_once(ROOT . DIRECTORY_SEPARATOR . 'config/bootstrap.php');
However, when using the same ROOT while including the css within the HTML seems to create a problem.
<html>
<head>
<title>PrePress ยท Login</title>
<link type="text/css" href=<?php echo ROOT . DS . 'views/type.css ?> rel="stylesheet">
</head>
<body>
Test
</body>
</html>
On tracing the path of the CSS file, the full path starts with http://localhost:8888/Users/.... Here I simply want my path to start from /Users/ which will be able to find my css file, whereas having the localhost changes the path and the file can no longer be found.
<link type="text/css" href="<?php echo $_SERVER["DOCUMENT_ROOT"]."/views/type.css"; ?>" rel="stylesheet" />
You do not need to use that format in an href. Just use
<link type="text/css" href="views/type.css" rel="stylesheet">
To give a relative address, which makes the code much more transportable
use
<?php $path = glob($_SERVER["DOCUMENT_ROOT"]."/views/type.css"); ?>
<link type="text/css" href="<?php $path; ?>" rel="stylesheet" />
You have to set the base url and that should link to your project folder. If you are not using a framework then I suggest you do.
Once you have set your base url you can call css and javascript from your header and footer respectively, and include the header and footer on your pages i.e $this->load->view('includes/header); and $this->load->view('includes/footer);
This is how you would typically call your scripts, I have only mentioned the href property within the tags as you should know the rest.
<script href="<?php echo base_url('link to your script goes here');?>" />
<link href="<?php echo base_url('link to your sheet goes here);?> />

How to add favicon.ico to site using document root

I tried to add icon with code
<link rel="shortcut icon" href="<?php include($_SERVER['DOCUMENT_ROOT'].'/imageslogos /favicon.ico'); ?>" />
When I look at the source code it showed lots of ? a few letters and numbers
When I clicked on this it said
The requested URL's length exceeds the capacity
limit for this server.
How do I add the icon from document root
You shouldn't use the include function since the link tag needs a reference.
Try this
<link rel="shortcut icon" href="
<?php echo $_SERVER["DOCUMENT_ROOT"]."/imageslogos/favicon.ico"; ?>
"/>

Where can i set the location of the css file in wordPress using php?

I am using wordpress and am trying to link to the stylesheet:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
It is not recognizing that link tag, because I think the bloginfo('stylesheet_url') part is not working correctly.
Where can I set the location of the stylesheet url in wordpress?
This is what should be specified:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" />
You are specifying correctly, make sure that you have put the CSS file in the root of your theme folder and the CSS file is named style.css
Another solution for those who want their stylesheet inside a subdirectory such as /css is to use bloginfo('template_url') instead of bloginfo('stylesheet_url')
Append the directory and stylesheet name inside the link href and outside the PHP tags
e.g.:
<link rel="stylesheet"
href="<?php bloginfo('template_url'); ?>/css/style.css"
media="screen" />
If (OOPS=='where did my background images go') { add relative path to image references in style sheet i.e. url(images/mybackground.jpg) becomes url(../images/mybackground.jpg) }

Categories