将.htaccess文件合并为silverstripe和squeezr

时间:2014-07-02 09:51:35

标签: .htaccess mod-rewrite silverstripe

我正在尝试将两个.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]

如果您在此问题中需要更多信息,请告诉我,我会补充一下。

1 个答案:

答案 0 :(得分:2)

你应该能够只结合2.似乎没有任何冲突

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


编辑:

在你的问题中,你还提到你要从sqeezer中排除cms,这个想法是有道理的,然而,你发布的RewriteRule根本没有,事实上如果没有,我会感到惊讶抛出一个错误。 上述规则唯一要做的事情(如果它可以工作),将排除squeezr文件被重写为框架,但这绝不会发生,因为之前的RewriteCond已经否定了(SilverStripe确实如此)不重写现有文件。)

所以您需要做的是实际向2个squeezr规则添加RewriteCond,告诉他们不要使用cmsframework

我相信添加以下两个条件(就在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>