dongli8722 2019-06-04 08:59
浏览 133

在url中添加操作后,没有获取.css和.js文件

I am making an application. If my request with url: http://localhost/invoice/public_html/index.php/string-inventory Everything works fine.

If I request with url: http://localhost/invoice/public_html/index.php/string-inventory/new-record or http://localhost/invoice/public_html/index.php/string-inventory/

My application doesn't server right .css or Js. I solved this type of issue from index.php ( no css and js files ) to index.php/ ( with css and js files ) while redirecting to whole different page. But that's not the right way to do. And I am getting 404 for .css and .js files for many pages with same context.

If I comment

RewriteCond %{REQUEST_URI} !..css$ [NC] RewriteCond %{REQUEST_URI} !..js$ [NC]

Then there is 404 but the file is not being served

My .htaccess

Turn rewriting on

Options +FollowSymLinks
RewriteEngine On

# Redirect requests to index.php

RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !.*\.png$ [NC]
RewriteCond %{REQUEST_URI} !.*\.jpg$ [NC]
RewriteCond %{REQUEST_URI} !.*\.css$ [NC]
RewriteCond %{REQUEST_URI} !.*\.gif$ [NC]
RewriteCond %{REQUEST_URI} !.*\.js$ [NC]

#RewriteCond $1 !^(../src)

 RewriteRule .* index.php?page=$1 [NC,L,QSA]

My expected url for .css should be http://localhost/invoice/src/css/mystyles.css

Where it is http://localhost/invoice/public_html/src/css/mystyles.css

but If there is not action after controller it works fine. and I do get served expected file. Same for Js.

Need anything, just ask

  • 写回答

1条回答 默认 最新

  • duanlei8119 2019-06-04 09:08
    关注

    I can not look into your filestructure but it appears your /invoice is your project url, and the folder 1 up from public_html is actually your public root folder.

    I can recommend you adapt your apache settings (usually /etc/apache2/sites-available) for your project in a way that the public_html folder is the actual public folder. This will solve the above issue.

    Another tip for your .htaccess file. You can check before you rewrite if the requested url is not in fact an existing file (!-f) or directory (!-d) instead of having to define every possible filetype in a list.

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^?]*)$ index.php?rt=$1 [NC,L,QSA] (or whatever rewrite you want to do)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?