【问题标题】:Combine the .htaccess files for silverstripe and squeezr合并 silverstripe 和 squeezr 的 .htaccess 文件
【发布时间】:2014-07-02 09:51:34
【问题描述】:

我正在尝试将两个 .htaccess 文件合并为一个:

https://github.com/silverstripe/silverstripe-installer/blob/3.1/.htaccess

https://github.com/jkphl/squeezr/blob/master/.htaccess

我还想从任何 squeezr 规则中排除 CMS(即指向 http://www.mysite.co.nz/admin/.... 的链接不应通过 squeezr 运行。

基本上把两个.htaccess文件合并起来,写silverstripe的最终重定向规则如下:

RewriteRule (?!^squeezr|admin)^.*$ framework/main.php?url=$1 [L,QSA,NC]

如果您需要有关此问题的更多信息,请告诉我,我会添加。

【问题讨论】:

    标签: .htaccess mod-rewrite silverstripe


    【解决方案1】:

    你应该可以把 2 结合起来。似乎没有任何冲突

    https://gist.github.com/24b48c12d82c73e60a37


    编辑:

    在您的问题中,您还提到您想从 sqeezer 中排除 cms,这个想法是有道理的,但是,您发布的 RewriteRule 根本没有,事实上,如果这没有引发我会感到惊讶错误。 上述规则唯一会做的事情(如果可以的话)就是排除 squeezr 文件被重写到框架,但这无论如何都不会发生,因为之前的RewriteConds 已经否认了这一点(SilverStripe 不会重写现有文件)。

    所以你需要做的实际上是在 2 squeezr 规则中添加一个RewriteCond,告诉他们不要使用cmsframework

    我相信添加以下 2 个条件(就在 squeezr 规则之前)会做到这一点:

    RewriteCond %{REQUEST_URI} !cms # exclude the silverstripe cms
    RewriteCond %{REQUEST_URI} !framework # exclude the silverstripe framework which is by 
    

    (您也可以在此处将其视为要点的差异:https://gist.github.com/Zauberfisch/d681474df67ced83ec1f/revisions


    完整的配置文件:

    ErrorDocument 404 /assets/error-404.html
    ErrorDocument 500 /assets/error-500.html
    
    <Files *.ss>
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Files>
    
    <Files web.config>
        Order deny,allow
        Deny from all
    </Files>
    
    <Files ~ "\.ya?ml$">
        Order allow,deny
        Deny from all
    </Files>
    
    
    
    <IfModule mod_rewrite.c>
        Options +FollowSymlinks
    
        # Start the rewrite engine
        RewriteEngine On
        RewriteBase /
    
    # REDIRECT ANY DIRECT IMAGE REQUEST TO A CACHED VERSION
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteCond %{ENV:REDIRECT_BREAKPOINT} !\d+px
        RewriteCond %{QUERY_STRING} !^([^&]*&)*squeezr=(0|false|no)
        RewriteCond %{HTTP_COOKIE} squeezr.images=(\d+px) [NC]
        RewriteCond %{REQUEST_URI} !cms # exclude the silverstripe cms
        RewriteCond %{REQUEST_URI} !framework # exclude the silverstripe framework which is by the cms
        RewriteRule ^(.+)(\.(?:jpe?g|gif|png))$ squeezr/cache/$1-%1$2 [NC,E=BREAKPOINT:%1,L]
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # Please make sure that you set this path     ^^^     to the squeezr root directory that is also specified
    # for the SQUEEZR_ROOT constant in the common engine configuration (SQUEEZR_ROOT/conf/common.php). If you
    # apply the default setup for squeezr (i.e. put everything into a directory named "squeezr" under your
    # website's document root), then you shouldn't have to change anything.
    #############################################################################################################
    
    
    # REDIRECT ANY DIRECT CSS REQUEST TO A CACHED VERSION
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteCond %{ENV:REDIRECT_BREAKPOINT} !\d+px
        RewriteCond %{QUERY_STRING} !^([^&]*&)*squeezr=(0|false|no)
        RewriteCond %{HTTP_COOKIE} squeezr.css=(\d+x\d+@\d+(?:\.\d+)?) [NC]
        RewriteCond %{REQUEST_URI} !cms # exclude the silverstripe cms
        RewriteCond %{REQUEST_URI} !framework # exclude the silverstripe framework which is by the cms
        RewriteRule ^(.+)\.css$ squeezr/cache/$1-%1.css [NC,E=BREAKPOINT:%1,L]
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # See above for hints on      ^^^     this path.
    #############################################################################################################
    
    ### SILVERSTRIPE START ###
        RewriteRule ^vendor(/|$) - [F,L,NC]
        RewriteRule silverstripe-cache(/|$) - [F,L,NC]
        RewriteRule composer\.(json|lock) - [F,L,NC]
    
        RewriteCond %{REQUEST_URI} ^(.*)$
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_URI} !\.php$
        RewriteRule .* framework/main.php?url=%1 [QSA]
    
        RewriteCond %{REQUEST_URI} ^(.*)/framework/main.php$
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule . %1/install.php? [R,L]
    ### SILVERSTRIPE END ###
    </IfModule>
    
    
    #############################################################################################################
    # Additional stuff for improving your website's delivery performance
    #############################################################################################################
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css text/javascript text/json text/x-json text/x-json-stream application/x-javascript application/json application/x-json application/x-json-stream application/.*xml.* multipart/x-json-stream multipart/x-mixed-replace image/svg+xml
    </IfModule>
    <IfModule mod_expires.c>
    
        ExpiresActive on
    
        # Images
        ExpiresByType image/gif "access plus 35 days"
        ExpiresByType image/png "access plus 35 days"
        ExpiresByType image/jpg "access plus 35 days"
        ExpiresByType image/jpeg "access plus 35 days"
    
        # Text based files
        ExpiresByType text/css "access plus 35 days"
        ExpiresByType text/xml "access plus 35 days"
        ExpiresByType text/javascript "access plus 35 days"
        ExpiresByType application/x-shockwave-flash "access plus 35 days"
    
        # Default expiration
        ExpiresDefault "access plus 1 days"
    
    </IfModule>
    

    【讨论】:

    • 同意,我只是查看了两个配置文件,两者都受限于不同的标准,所以我看不出它们有任何冲突)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 2011-11-20
    • 1970-01-01
    • 2011-10-24
    • 2017-07-03
    • 2021-09-09
    • 1970-01-01
    相关资源
    最近更新 更多