F3 changes relative URi of css files

眉间皱痕 提交于 2019-12-23 15:07:09

问题


I am a newb experimenting with F3. My sample app is basically working but references to css files get changed and result in not being found. It looks like a .htaccess problem but I can't seem to fix it.

My css files are specified as

<link rel="stylesheet" href="ui/css/base.css" type="text/css" />
<link rel="stylesheet" href="ui/css/theme.css" type="text/css" />
<link rel="stylesheet" href="lib/code.css" type="text/css" />

My .htaccess file looks like

RewriteBase /blog/

RewriteCond %{REQUEST_URI} \.ini$
RewriteRule \.ini$ - [R=404]

RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

This is in /blog under doc root and /ui and /lib are directories in /blog

Somehow the css files get referenced as /blog/view/ui/css when accessing a route template ('view' is the route name) I don't understand why this reference gets changed. Can you help?


回答1:


It's because you're referencing your CSS files relatively. Either you add a "/" like the following

<link rel="stylesheet" href="/lib/code.css" type="text/css" />

or you use F3's internal variable to determine the base path which might be better if your app is inside a subdirectory. Thus you should write the following in your template (at least if you're using the Template class)

<link rel="stylesheet" href="{{@BASE}}/lib/code.css" type="text/css" />


来源:https://stackoverflow.com/questions/27828540/f3-changes-relative-uri-of-css-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!