doujiebo9849 2019-01-25 08:20
浏览 55

如何使用.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.

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 matlab实现基于主成分变换的图像融合。
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊