How to use mod_Rewrite to check multiple folders for a static file

前端 未结 4 1408
生来不讨喜
生来不讨喜 2021-01-05 14:51

What are the mod_Rewrite rules for checking multiple folder locations for a given file. For instance, if I have a folder structure of:

public/
    css/
             


        
相关标签:
4条回答
  • 2021-01-05 15:38

    Try this:

    # Loads files from production server
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (library1|library2)/(.*)$ http://production.com/$1/$2 [R=302,L,NC]
    

    To achieve this:

    something.dev/library1/style.css -> production.com/library1/style.css something.dev/library2/vendor/css/style.css -> production.com/library2/vendor/css/style.css

    0 讨论(0)
  • 2021-01-05 15:40

    RewriteMap Directive might help.

    0 讨论(0)
  • 2021-01-05 15:44

    Try these rules:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{DOCUMENT_ROOT}/library1%{REQUEST_URI} -f
    RewriteRule ^css/.+ library1%{REQUEST_URI} [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{DOCUMENT_ROOT}/library2%{REQUEST_URI} -f
    RewriteRule ^css/.+ library2%{REQUEST_URI} [L]
    
    0 讨论(0)
  • 2021-01-05 15:52

    Possibly the server variables do not contain what you think. Try increase the logging to debug, so you can see exactly what is going on.

    0 讨论(0)
提交回复
热议问题