【问题标题】:Using mod_rewrite to access images better?使用 mod_rewrite 更好地访问图像?
【发布时间】:2012-10-19 06:56:39
【问题描述】:

在我的应用程序中,我的 javascript 文件在文件夹 /web_root/inc/js/ 中,我的图像在 /web_root/inc/images/ 中,我的 css 文件在 /web_root/inc/css/ 中。

我不喜欢这些链接,所以我想我会在它们上使用 mod_rewrite。是否推荐和/或可能使用 mod_rewrite,所以在我的代码中我可以包含图像、JS 和 CSS 文件,就像在以下示例中一样:

<img src="images/img.png" alt="image" />

代替:

  <img src="inc/images/img.png" alt="image" />

【问题讨论】:

    标签: mod-rewrite


    【解决方案1】:

    在您的 web_root 文件夹中添加一个 .htaccess 文件并包含下一个规则

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^images/(.*) http://%{HTTP_HOST}/inc/images/$1 [R=301,L]
    </IfModule>   
    

    我做到了,它对我有用。

    希望能帮到你

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2013-09-17
      • 2011-11-11
      • 2017-02-26
      • 1970-01-01
      相关资源
      最近更新 更多