0

My code is working on production but its not working in localhost. i think its because of url redirect done in htaccess file.

when i open localhost/project_1.0/index.php page opens but images are not displaying. In source code on clicking its trying to load from localhost/images/e1.jpg but it should be localhost/project_1.0/images/e1.jpg

This same applies for css and javascript file also.

my htaccess file code:

RewriteEngine on
RewriteBase /

#Force non-www:
RewriteCond %{HTTP_HOST} www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteRule ^index\.php$ / [NC,R=301,L]
  • 1
    Sounds more like the embedded links to the images use absolute paths, so paths with a leading slash (`/`). If so, then you have to _add_ redirection rules for that on your local system, or, preferably, you should fix the application to use relative links. – arkascha May 22 '16 at 07:01
  • I suggest you add such a link to the question above as you can see it in the html page loaded into your browser. There is an `edit` button below your question for that. Thanks! – arkascha May 22 '16 at 07:14

1 Answers1

0

For this problem I used to do like this,

<?php
$host = $_SERVER['HTTP_HOST'];
if($host == 'something.com' || $host == 'www.something.com' ){
    $base = 'http://'.$host.'/';
}else{
    $base = 'http://'.$host.'/local_directory/';
}
?>
<html>
<head>
<base href="<?=$base?>" />
</head>
<body>

</body>
</html>