代码之家  ›  专栏  ›  技术社区  ›  Dan Sosedoff

重写静态内容的URL

  •  1
  • Dan Sosedoff  · 技术社区  · 16 年前

    我在apache2上的当前.htaccess设置中遇到了静态文件url重写问题。

    我的应用程序结构是:

    /siteroot
    /siteroot/app
    /siteroot/lib
    /siteroot/...
    /siteroot/public <- all the static files (images, js, etc.) stored here
    /siteroot/index.php
    /siteroot/.htaccess
    

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/$0 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    2 回复  |  直到 16 年前
        1
  •  3
  •   Gumbo    16 年前

    测试重定向是否合理:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{DOCUMENT_ROOT}/public/$0 -f
    RewriteRule ^.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/$0 [L]
    
        2
  •  0
  •   Kev    16 年前

    RewriteRule ^(css|js|images|etc)/.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/$0 [L]
    
    推荐文章