URL 重写 - 遵循我的规则并保留物理文件
mod_rewrite 中的菜鸟在这里...我正在开发一个新站点并使用 mod_rewrite。
问题是,当我激活 .htaccess 中的规则时,我的 CSS 文件和图像链接变得不可读。
例如,我有这样的: http://www.dico2rue.com/dictionnaire.php?idW =675&word=Resto-basket 我改成这样: http://www.dico2rue.com/dictionnaire/675/Resto-basket
我知道这可能是因为浏览器正在寻找 CSS 文件 http://www.dico2rue.com/dictionnaire/675/css/general.css 而不是基本目录,但是我希望有一种方法可以单独保留物理文件,只解析其他 URL 以避免完整路径(这显然会减慢下载速度) 速度...?...)。
谢谢。
Noob in mod_rewrite here...I'm developing a new site and using mod_rewrite.
The problem is, when I activate my rules in .htaccess, my links to CSS files and images become unreadable.
For example, I had this:
http://www.dico2rue.com/dictionnaire.php?idW=675&word=Resto-basket
That I transformed to this:
http://www.dico2rue.com/dictionnaire/675/Resto-basket
I know it's probably because the browser is looking for the CSS file in the
http://www.dico2rue.com/dictionnaire/675/css/general.css instead of the base directory, but I was hoping there was a way to to leave physical files alone, and only parse other URLs in order to avoid full paths (which apparently slows down downloas speed...?...).
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题和mod_rewrite没有任何关系;您只需在链接标记的 src 属性中提供 CSS 文件的有效 URL。您可能想要使用的相对 URL 是“/css/general.css”。请参阅相对 URL rfc。
另一方面,您对 mod_rewrite 的想法可能有点偏差。在您的示例中,您实际上是在服务器的 /dictionnaire/675/ 路径中提供资源。事实上,您使用 mod_rewrite 而不是其他方法来执行此操作并没有什么区别。
This problem doesn't have anything to do with mod_rewrite; you just need to provide a valid URL to your CSS file in the src attribute of your link tag. The relative URL you probably want to use is "/css/general.css". See the relative URL rfc.
On another note, your thinking about mod_rewrite might be a little off. In your example you are actually providing a resource in the /dictionnaire/675/ path of your server. The fact that you are using mod_rewrite to do it instead of some other method makes no difference.
您需要添加这些行来检查它是否不是重写规则之前的文件或目录
you need to add these lines to check if it's not a file or directory right before the rewrite rules