生产代码无法在localhost中运行。是因为htaccess?

时间:2016-05-22 06:52:49

标签: php .htaccess localhost production-environment

我的代码正在进行生产,但它无法在localhost中运行。我认为这是因为在htaccess文件中完成了url重定向。

当我打开localhost / project_1.0 / index.php页面打开但图像没有显示。在源代码中点击它试图从localhost / images / e1.jpg加载,但它应该是localhost / project_1.0 / images / e1.jpg

这同样适用于css和javascript文件。

我的htaccess文件代码:

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 个答案:

答案 0 :(得分:0)

对于这个问题我曾经这样做过,

<?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>