如何排除CSS,JS,JPG,从mod_rewrite的规则GIF文件? [英] How do I exclude CSS, JS, JPG, GIF files from mod_rewrite rules?

查看:315
本文介绍了如何排除CSS,JS,JPG,从mod_rewrite的规则GIF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我迄今为止:

RewriteRule ^([A-Za-z0-9_]*)/?$ index.php?page=$1 [NC]
RewriteRule ^([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/?$ index.php?page=$1/$2 [NC]
RewriteRule ^([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/?$ index.php?page=$1/$2/$3 [NC]

我所有的CSS文件位于/ SSI ​​/.

All of my css files are located in /ssi/.

该网站结构本身/index.php?page=$whatever

The site structure itself is /index.php?page=$whatever

$无论有时包括/人的,所以如果我去/不管/ whatever2,我目前的规则,它假定的CSS位于/不管/ SSI ​​/ *。CSS。

$whatever sometimes includes /'s, so if I go to /whatever/whatever2, with my current rules, it assumes the css is located in /whatever/ssi/*.css.

我希望这一切是很有意义的。

I hope all of that makes sense.

所以,基本上我只是想能够写,说的条件,如果它是一个CSS文件,不应用这​​些规则。

So, basically I just want to be able to write a condition that says "if it's a css file, don't apply these rules."

感谢您的帮助,我可以得到:)

Thank you for any help I can get :).

推荐答案

这是您所遇到的问题不在于mod_rewrite的被应用到css文件,而是在你的HTML给你的CSS路径是相对的。浏览器仅仅是请求从正确的相对路径的CSS。你真的有两个选择。

The problem that you are experiencing is not that the mod_rewrite is being applied to css files, but rather that the paths in your html to your css is relative. The browser is simply requesting the css from the correct relative path. You really have two options.


  1. 请您路径的CSS相对于域的,而不是页面(例如使用/ssi/styles.css代替SSI / Styles.css中的)

  2. 创建一个重写规则,以所有的CSS重定向到正确的URL。 (例如,重写规则(*的CSS)/ SSI ​​/ $ 1

这篇关于如何排除CSS,JS,JPG,从mod_rewrite的规则GIF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆