doumicheng6732 2011-08-28 15:04
浏览 27
已采纳

PHP / Htaccess - 加载器的问题

I have an htaccess file in the root that redirects every request of a page to a specific file:

RewriteCond %{REQUEST_URI} !^/loader.php(.*)?$ [NC]
RewriteRule ^(.*)$         /loader.php?url=$1    [QSA,L]

Now the redirect is easy in the loader.php

include($_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['url']);

I just include the URL,admin/index.php for example.

If I leave the code as is the loader will include the file and print the correct HTML, but it will not load any CSS or JS scripts. If I put echo "test"; just before the include, the loader will load the CSS file. It's something that is killing me. Do I have to specify something in the HTTP header?

I already tried putting <base url="" /> in the header of index.php with no result, but another strange thing is that with Chrom if I inspect the page and click on the link I'll see the right CSS.


Update 1

I printed the headers_list();. I noticed one thing - when I print an echo in headers_list, an array shows the content-type, so I tried to add it on my own with the header() function but with no result. Still working on it.


Update 2

I've noticed another thing; if I put a <style></style> tag with some CSS it will work fine, but if I use the <link /> tag it doesn't. This doesn't make any sense.

  • 写回答

1条回答 默认 最新

  • dsbckxk165039 2011-08-28 16:07
    关注

    You have to send the correct MIME headers for css and javascript (and images etc.). Easiest is to just let apache handle those requests. Put all the CSS, JS and images in a folder named 'assets' or something and change the htaccess to

    RewriteCond %{REQUEST_URI} !^/assets/
    RewriteCond %{REQUEST_URI} !^/loader.php(.*)?$ [NC]
    RewriteRule ^(.*)$         /loader.php?url=$1    [QSA,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真