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 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥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系统的像差计算