.htaccess url:在本地主机Xampp上重写缺少的css javascript和图像文件

时间:2014-09-08 09:11:42

标签: php css .htaccess mod-rewrite

我是.htacees的新人。我正在尝试使用模式重写为用户创建用户友好的URL。我的问题是,当我使用 .htaccess re:write 打开" user.php" 页面时,它无法加载 CSS文件图片文件,并显示如下。

Sign up
My account
Hi
    My Profile
    My account
    Logout
    Help
    © 2014 Company, Inc.

我有一个类似的链接:

http://localhost/www.zeeshan.com/user.php?name=zeeshan06

新的链接是类似的,它的工作100%适合我。

http://localhost/www.zeeshan.com/user/zeeshan06

我的.htaccess文件

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /www.zeeshan.com/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/([^/]+)$ user.php?name=$1 [NC,L]

我的CSS文件路径css / style.css,css / bootstrap.css,www.zeeshan.com文件夹中的bootstrap.min.css

<head>
<link href="style.css" rel="stylesheet" type="text/css"/>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>

out .htaccess页面运行良好并显示div,panel等的css但是使用.htaccess re:写下它无法打开 css文件图像文件。请帮我解决我的问题。感谢..

2 个答案:

答案 0 :(得分:1)

CSS文件的路径是相对的。因此,当您加载http://localhost/www.zeeshan.com/user/zeeshan06时,您的浏览器会在名为http://localhost/www.zeeshan.com/user/的文件夹中查找CSS文件。您需要将路径更改为:

<head>
<link href="/www.zeeshan.com/style.css" rel="stylesheet" type="text/css"/>
<link href="/www.zeeshan.com/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="/www.zeeshan.com/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>

答案 1 :(得分:0)

如果您在<base>标记内的每个页面上放置一个静态链接,则需要在部署后重新进行更改。

使用它:

<base href= "<?php echo "http://".$_SERVER['HTTP_HOST']."/your_folder/" . "/>" ; ?>"

因此您可以上传到制作中,永远不需要再次更改。

相关问题