douhuzhi0907 2015-06-27 22:46
浏览 18

写完.htaccess后css不工作

I was trying to get rid of my file extensions using .htaccess, it worked, but right now my CSS and images has stopped working. I have tried different things, but it's still not working. Please! I need help with this. Thanks in advance. All my php files are in the same directory which is the root folder and my css and image folder is in a different folder in my root folder. here is my code

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*/.php$ %{REQUEST_FILENAME}.php [L]
RewriteRule ^(css|img) - [L]
  • 写回答

1条回答 默认 最新

  • doujia1871 2015-06-28 04:37
    关注

    To add .php you just need this rule:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^([^.]+?)/?$ $1.php [L]
    

    If you have a trailing slash in your pretty URL like http://example.org/file/ then css/js relative paths will be resolved to /file/css/ instead of /css/ hence causing 404 for css/js files.

    To fix that you can add this in the <head> section of your page's HTML:

    <base href="/" />
    

    so that every relative URL is resolved from that base URL and not from the current page's URL.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大