我是.htacees的新手。我正在尝试使用模式重写为用户制作用户友好的URL。我的问题是,当我使用.htaccess re:write打开"user.php"页面时,它无法加载CSS文件或图像文件 我有一个类似的链接: 新的链接是类似的东西,它的工作100%对我来说是正确的。 我的.htaccess文件 我的CSS文件路径CSS/style.CSS,CSS/bootstrap.CSS,bootstrap.min.CSS,位于www.zeeshan.com文件夹中 使用out.htaccess页面可以很好地显示div、panel等的cssre:write-its无法打开css文件和图像文件Sign up
My account
Hi
My Profile
My account
Logout
Help
© 2014 Company, Inc.
http://localhost/www.zeeshan.com/user.php?name=zeeshan06
http://localhost/www.zeeshan.com/user/zeeshan06
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]
<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>
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>
如果在<base>
标记内的每个页面上都放置了一个静态链接,则需要在部署后再次对其进行更改。
使用这个:
<base href= "<?php echo "http://".$_SERVER['HTTP_HOST']."/your_folder/" . "/>" ; ?>"
这样你就可以上传到生产中,再也不需要更改了。