如何使用.htaccess重定向CSS文件?

I'm working with PHP and MVC and now I need to redirect my CSS files to the proper view.

What I have

My .htaccess file already has this:

Options -MultiViews
RewriteEngine On 

RewriteBase /mvc/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule "^(.+)$" "index.php?url=$1" [QSA]

The controller handles everything so my URL looks like this: localhost/mvc/{controller}/{action}/

My css files are located at localhost/mvc/css/{anyCSS}.css

And in the html code i write this for example: <link rel="stylesheet" href="forIndex.css">

What I tried already

I looked for some RewriteRules on the Internet already, but they didn't really work. This for example:

RewriteRule "^(.*).css$" "css/$1.css" [QSA,L]
RewriteRule "^([a-z]+\.css)$" "css/$1" [L]
RewriteRule "^(.+)\/(.+)\.css$" "css/$2.css" [QSA,L]

I tried those in Regex Testers as well but still couldn't find any way to do so.

Example

For example my url looks like this localhost/mvc/home/index/

home = controller
index = action(function/method)
/* By default it loads the index.php */ 

The index.php can't reach the css file when i link it like above. I also tried to link it with the subfolder path : href="css/forIndex.css".

If you need some more information, just let me know.

dtqu3278
dtqu3278 欢迎来到stackoverflow。如果你在RewriteCond%{REQUEST_FILENAME}之后添加规则RewriteRule“^(。*)。css$”“css/$1.css”[QSA,L]direclty会发生什么!-f?
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐