在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

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)