我的项目文件夹就像这样
*myProject(d:wamp/www/mywebsites/myProject)
@ ajax
@ asset
#all of php functions and database
@ newsPicture
#my post images
@ profilePicture
#user images
@ public
-js
-css
-img
-.htaccess //file
-index.php //file
-User.php //file
-Posts.php //file
@ view
-header.php //include in index.php
-footer.php //include in index.php
所以我把我的htaccess设置为这个
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Change /Posts.php?id=4 => /Posts/4
RewriteRule ^Posts/([A-Za-z0-9]*)$ Posts.php?id=$1 [L]
#Change /User.php?id=4 => /User/4
RewriteRule ^User/([A-Za-z0-9]*)$ User.php?id=$1 [L]
#Change /Sign.php => /Sign
RewriteRule ^([A-Za-z0-9]+)$ $1.php [L]
和我的html标题是这样的(view / header.php)
<link href="css/bootstrap.min.css" type="text/css" rel="stylesheet">
<link href="css/bootstrap-theme.min.css" type="text/css" rel="stylesheet">
<link href="css/Normalize.css" type="text/css" rel="stylesheet">
<link href="css/Fixer.css" type="text/css" rel="stylesheet">
所以当我在我的网址中传递参数像User / 2时,我的所有css和js都无法正常工作!我应该在header.php中使用绝对链接作为我的链接标记吗?像:
<link href="<?php echo dirname($_SERVER['PHP_SELF']);?>/css/Fixer.css" type="text/css" rel="stylesheet">
请帮助我tnx!
答案 0 :(得分:1)
您必须在开头添加斜杠来更改路径。
访问 www.yourdomain.com/path1 /
时服务器搜索 www.yourdomain.com/path1 /css/bootstrap.min.css
中的文件<link href="/css/bootstrap.min.css" type="text/css" rel="stylesheet">
<link href="/css/bootstrap-theme.min.css" type="text/css" rel="stylesheet">
<link href="/css/Normalize.css" type="text/css" rel="stylesheet">
<link href="/css/Fixer.css" type="text/css" rel="stylesheet">