我有一个index.php文件,在本地主机/项目profile.php文件 我下面code。在我的.htaccess文件有本地主机/项目/ profile.php写的?U = SAM 访问本地主机/项目/ SAM
I have an index.php, profile.php files in localhost/project I've written following code in my .htaccess file to have localhost/project/profile.php?u=sam by visiting localhost/project/sam
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?u=$1
当我访问的http://本地主机/项目/ SAM 它diplays我想没有错误。但是,当我访问的http://本地主机/项目/ SAM / (尾随 / ),它显示纯文本,这意味着没有附加的CSS文件的页面。
When I visit http://localhost/project/sam it diplays what I want without errors. But when I visit http://localhost/project/sam/ (with trailing / ) it displays the page with plain text, that means the css file is not attached.
任何人都知道这样做的原因是什么?帮我解决此问题?
Anyone know the reason for this? And help me to solve this?
您可能正在使用相对URI路径引用这些外部资源。而相对URI解析的基本URI是当前文档的URI,如果没有指定,否则。
You are probably using relative URI paths to reference those external resources. And relative URIs are resolved on a base URI that is the URI of the current document if not specified otherwise.
于是就 /项目/ SAM使用相对URI路径像
这是解决以 CSS / style.css中
在 /project/css/style.css
;但在使用时, /项目/ SAM /
它解析为 /project/sam/css/style.css
。
So when using a relative URI path like css/style.css
on /project/sam
it is resolved to /project/css/style.css
; but when used on /project/sam/
it is resolved to /project/sam/css/style.css
.
您既可以由使用绝对URI路径解决这个问题 /project/css/style.css
或改变使用的 BASE
元素。但需要注意的是,后者将影响的所有的相对URI,而不只是相对的URI路径。
You could fix this by either using the absolute URI path /project/css/style.css
or by changing the base URI with the BASE
element. But note that the latter will affect all relative URIs and not just relative URI paths.