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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了