drupal 7, paths and urls are not working properly I'm developing a website on my localhost. I have a problem with urls.

for a url like this 

http://localhost:81/my_website/library


I should output image src this way :

&lt;img src="&lt;?php print $directory; ?&gt;/image/header/headerR.png"/&gt;


but when the above url is changed to this

http://localhost:81/my_website/library/


I should output image src this way :

&lt;img src="../&lt;?php print $directory; ?&gt;/image/header/headerR.png"/&gt;


I mean it should refer to the parent. my website has also contextual filter which must be inserted after library/ .is there any general solution for handling such thing?
Use the global variables for resolving the issue of path of files as below:


Use base_path if your fine with domain name not to be included:
It will return path respect to the drupal root.
Eg:  "/" for drupal root(http://localhost:81/my_website), and
"/images/header" for http://localhost:81/my_website/image/header/header

Example:


/*Assuming image path: http://localhost:81/my_website/image/header/headerR.png*/
global $base_path; /* will return "/" for http://localhost:81/my_website*/
$image_path = $base_path . 'image/header/headerR.png';



Note: Don't use trailing slash / for adding path of files with $base_path as it adds a "/" to the beginning and end of the returned path. 
Use base_url if you want to get the full path: It will return
base URL of the Drupal installation.

Example:


/*Assuming image path: http://localhost:81/my_website/image/header/headerR.png*/
global $base_url; /* will return http://localhost:81/my_website in you case*/
$image_path = $base_url . '/image/header/headerR.png';