Cant link images on subdomain - php

Can someone explain why linking local image files doesnt work under subdomain.
I have a website:
http://example.com/site/index.php
Icons and images are under icons directory.
http://example.com/site/icons/icon.png
I include them in site like this:
<img src="icons/icon.png">
This works fine when accessing site from first url.
However, when i use subdomain:
http://site.example.com
Icons doesnt display anymore.
I notice that even in browser, it doesnt exist.
http://site.example.com/icons/icon.png
Happy new year!

You need to check where your subdomain is pointing to. It seems from your description that the folder which it is pointing to contains an index.php file that is identical to the index.php file in the site folder, which gives you the feeling that the subdomain is actually pointing to the site folder, but it's not.
You need to change the subdomain in the control panel to point to the value /site. Notice the forward slash.

Related

Issues with php include in sub domain

I just uploaded my site but am having issues with sub domain and php include.
First I have a directory /main/ and all it content are okay in localhost and also when I uploaded online until when I decided to forward www.main.example to main directory.
Now if I browse it this way www.main.example files that I include will not work, and also my css, but I manage to add full site name to my css and js like www.example.com/css/page.css and is working. So can someone help me with php path or any htaccess code that can help me fix this?
I tried this to but not working
include_once('../_inc/functions.php');
include_once(__DIR__ . '/../_inc/userlocation.php');

Set-up include path for menu navigation so page links know where the site root is located in order to not break links

I have not been successful getting my remote server environment to behave like my testing server environment -nor visa versa- in regard to my navigations "include code" that I've included on my various pages (these pages reside inside other folders in the site).
My Menu shows up fine in the pages calling the include to this page this way...
<?php include("../includes/navigation.php"); ?>
But my MAMP testing server seems to want me to also add the root folder in addition to my provided link in each of the menu items, so I altered the link by adding my site root folder, like this...
<a href="/mysite/courses/list.php"
and navigation menu seemed to work, going inside one folder and back out into another (then I realized it was no good when I tested it on my remote server).
I got bad/broken links.
So I changed to something like this for the remote server...
<a href="/courses/list.php"
Links seem to work on the remote, but I needed to fix it so that the code I go with works on both the testing and remote servers...
So, I'm trying to ~~understand/control/and fix~~ my include_once code to provide proper menu navigation for all my various pages whether I am on my testing server or on my remote server and wether I am in one folder or another. Is this possible? And am I approaching this the right way?
(Currently, I have my root folder with an index page, then inside that, I have 3 folders with misc pages inside them, one of these folders (includes) holds my navigation.php page)
I have been searching for how to get my pages (located in various folders) to recognize where they were, in relation to the sites root folder. As a result of searching I concluded to insert this code into the list.php page in my "courses folder"...
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/includes/navigation.php";
include_once($path);
?>
on one of my pages and then tested it in my testing server (MAMP) - but now the menu does not even show up...I also tried...
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "../includes/navigation.php";
include_once($path);
?>
So I am seeking help in understanding - what am I missing in my understanding/execution to get the pages now to show the navigation menu as well as know where it is in relation to the root.
I would welcome any comments to help me understand how to connect the dots to solve this problem. As I read in another post saying to someone else there was a problem with where their site root folder was pointing (that it was pointing to the server root folder, not the site root folder)-
How would I know if this is what my problem is? How do you check this?
I had this same exact problem going on. What I did to solve it was instead of simply using "..includes/nav.php" I used an absolute path to the file. It should look something like this:
"var/www/html/includes/nav.php"
This specifies the exact route to the file. You can find this through your hosting file management page. Log into the file management, find the nav file within the folders, and use the exact url of the file.

PHP use full path from root to link to file instead of going from parent

I need to be able to access a file in a folder located in the root directory on each of my pages.
Is there a piece of code I can use to type out the full directory going from the root folder to the specific folder I want and be able to copy onto each page without having to change the code?
For more clarification, it's hard to word, but I want to be able to link top my CSS file in the directory /css on each page without manually having to put ../../ etc.
Or does anyone else know the best way to link one style sheet to each page with ease?
If the root of your website has the path / (in other words, the address you type for the root of your website is something like http://mydomain.com/) then you can simply refer to your CSS files using /my.css or /css/my.css in all pages. The leading / tells the browser to look for these files relative to the root of your website.
You should be able to use a relative path of /folder path that will be accessible from all your pages.
You should also be able to do it the same was Cristian is recommending with:
$folder = $_SERVER['DOCUMENT_ROOT']."/folder path";

set files path in zend framework

im updating a project , the problem is that all images src and header links and etc have path like this:
src="/media/js/hoverIntent.js"
and i cant see every thing ok on localhost
when i delete the first '/' in src every thing is ok. but the project is very big and i cant delete one by one ,
how can i solve this problem.
Use mod_rewrite to point the failing URLs to the correct ones.
As example: your application uses URLs like /media/js/hoverIntent.js but everytime the URL begins with /media and you have the data stored on your dev server in /myapp/media/.... In this case you can solve it by placing following .htaccess in your root folder:
RewriteEngine On
RewriteRule ^media/(.*)$ /myapp/media/$1
Sure, you need to adjust the target URL of your files on localhost

Setting a root directory for accessing files from subfolders?

I am trying to create a root directory on my localhost(using xampp) so that I can link to images and folders found on the root from subfolders. So my directory is built like seen below.
Also, would this method work when the site is uploaded on the web? or would I have to change document root to http:// links to my site?
F = folder
f = file
My Site
-------
[f] index.html
[f] logo.html
[F] css -> [f] main.css
[F] news -> [F]1 -> [f] 1.html
[F] images -> [f]logo.jpg
logo.html will be included using PHP on every html page.
So if I include the logo.html in both index.html & news/1/1.html link to image doesn't work since the news file is on a different folder and link to the images folder changes.
I tried this using PHP but it seems I am doing it wrong:
<?php $root = $_SERVER['DOCUMENT_ROOT'].'/My Site/'; echo $root .'/images/logo.jpg';
?>
$_SERVER['DOCUMENT_ROOT'] gives you the real file-system path, not the path returned by Apache.
To link to the resource you need to use the HTTP path. If you want to link from the root you just need something like /images/logo.jpg
I found that on my PHPBB3.1 driven website using the "Pages" addin, the relative link would not remain 'static' in some link buttons at the top of my site.
From the PHPbb3 index page a link such as app.php/page/FT would produce an address of http://earth/forum/app.php/page/FT (Correct) ,but from the "Pages add in) that same link produced http://earth/forum/app.php/page/app.php/page/FT (incorrect).
I started looking for a way to set my page relative to the root of the web. I could NOT use absolute links because my site is replicated on other servers. I found the answer by trial and error. Simply add several ../../../ like this ../../../forum/app.php/page/FT
and it works.
Perhaps not the best of computer programming but it does the job.
In a nutshell with each ../ you step back a directory, put too many in and it goes back to the root but cannot go back any further!

Categories