From 0d789bf63684fe8d930a13a2b6290403021ec511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Lochmu=CC=88ller?= Date: Fri, 29 Mar 2019 18:16:26 +0100 Subject: [PATCH] Feature: Add port to static file cache path --- Classes/Cache/StaticFileBackend.php | 4 +- Documentation/Configuration/Htaccess.rst | 48 +++++++++++++----------- ext_conf_template.txt | 4 +- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Classes/Cache/StaticFileBackend.php b/Classes/Cache/StaticFileBackend.php index 366a973be598..e6436b1106d8 100755 --- a/Classes/Cache/StaticFileBackend.php +++ b/Classes/Cache/StaticFileBackend.php @@ -262,11 +262,9 @@ protected function getCacheFilename(string $entryIdentifier): string $parts = [ $urlParts['scheme'], $urlParts['host'], + isset($urlParts['port']) ? (int)$urlParts['port'] : ('https' === $urlParts['scheme'] ? 443 : 80), ]; - // Add by configuration? - // $parts[] = isset($urlParts['port']) ? (int)$urlParts['port'] : 80; - $path = \implode('/', $parts) . '/' . \trim($urlParts['path'], '/'); $cacheFilename = GeneralUtility::getFileAbsFileName(self::CACHE_DIRECTORY . $path); $fileExtension = (string)PathUtility::pathinfo(PathUtility::basename($cacheFilename), PATHINFO_EXTENSION); diff --git a/Documentation/Configuration/Htaccess.rst b/Documentation/Configuration/Htaccess.rst index 0a11938cd923..b38b51aa9168 100755 --- a/Documentation/Configuration/Htaccess.rst +++ b/Documentation/Configuration/Htaccess.rst @@ -24,38 +24,45 @@ This is the base .htaccess configuration. Please take a look for the default var RewriteRule .* - [E=SFC_HOST:%1] # Get scheme + RewriteRule .* - [E=SFC_PROTOCOL:http] RewriteCond %{SERVER_PORT} ^443$ [OR] RewriteCond %{HTTP:X-Forwarded-Proto} https RewriteRule .* - [E=SFC_PROTOCOL:https] - RewriteCond %{SERVER_PORT} !^443$ - RewriteCond %{HTTP:X-Forwarded-Proto} !https - RewriteRule .* - [E=SFC_PROTOCOL:http] - # Get port (not used at the moment) + # Get port RewriteRule .* - [E=SFC_PORT:80] - RewriteCond %{SERVER_PORT} ^[0-9]*$ [OR] + RewriteCond %{ENV:SFC_PROTOCOL} ^https$ [NC] + RewriteRule .* - [E=SFC_PORT:443] + RewriteCond %{SERVER_PORT} ^[0-9]*$ RewriteRule .* - [E=SFC_PORT:%{SERVER_PORT}] + # Full path for redirect + RewriteRule .* - [E=SFC_FULLPATH:typo3temp/tx_staticfilecache/%{ENV:SFC_PROTOCOL}/%{ENV:SFC_HOST}/%{ENV:SFC_PORT}%{ENV:SFC_URI}] + # Check if the requested file exists in the cache, otherwise default to index.html that # set in an environment variable that is used later on - RewriteCond %{ENV:SFC_ROOT}/typo3temp/tx_staticfilecache/%{ENV:SFC_PROTOCOL}/%{ENV:SFC_HOST}%{ENV:SFC_URI} !-f - RewriteRule .* - [E=SFC_FILE:index.html] - - # Note: https://github.com/lochmueller/staticfilecache/pull/90 (Please check the realurl configuration related to "appendMissingSlash". Perhaps you need an additional "/" in the rule above) - # RewriteRule .* - [E=SFC_FILE:/index.html] + # Note: With old RealURL structure perhaps you have to remove the "/" https://github.com/lochmueller/staticfilecache/pull/90 + # Note: We cannot check realurl "appendMissingSlash" or other BE related settings here - in front of the delivery. + # Perhaps you have to check the "SFC_FILE" value and set it to your related configution e.g. "index.html" (without leading slash). + # More information at: https://github.com/lochmueller/staticfilecache/pull/28 + RewriteCond %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH} !-f + RewriteRule .* - [E=SFC_FULLPATH:%{ENV:SFC_FULLPATH}/index.html] - # Set gzip extension into an environment variable if the visitors browser can handle gzipped content and the gz-file exists + # Extension (Order: br, gzip, default) RewriteRule .* - [E=SFC_EXT:] + RewriteCond %{HTTP:Accept-Encoding} br [NC] + RewriteRule .* - [E=SFC_EXT:.br] + RewriteCond %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH}%{ENV:SFC_EXT} !-f + RewriteRule .* - [E=SFC_EXT:] + RewriteCond %{ENV:SFC_EXT} ^$ RewriteCond %{HTTP:Accept-Encoding} gzip [NC] RewriteRule .* - [E=SFC_EXT:.gz] - RewriteCond %{ENV:SFC_ROOT}/typo3temp/tx_staticfilecache/%{ENV:SFC_PROTOCOL}/%{ENV:SFC_HOST}%{ENV:SFC_URI}%{ENV:SFC_FILE}%{ENV:SFC_EXT} !-f + RewriteCond %{ENV:SFC_EXT} ^\.gz$ + RewriteCond %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH}%{ENV:SFC_EXT} !-f RewriteRule .* - [E=SFC_EXT:] - # @todo check "br" as Accept-Encoding to add brotli support - - # Note: We cannot check realurl "appendMissingSlash" or other BE related settings here - in front of the delivery. - # Perhaps you have to check the "SFC_FILE" value and set it to your related configution e.g. "index.html" (without leading slash). - # More information at: https://github.com/lochmueller/staticfilecache/pull/28 + # Write Extension to SFC_FULLPATH + RewriteRule .* - [E=SFC_FULLPATH:%{ENV:SFC_FULLPATH}%{ENV:SFC_EXT}] ### Begin: StaticFileCache (main) #### @@ -63,21 +70,18 @@ This is the base .htaccess configuration. Please take a look for the default var RewriteCond %{QUERY_STRING} ^$ # It only makes sense to do the other checks if a static file actually exists. - RewriteCond %{ENV:SFC_ROOT}/typo3temp/tx_staticfilecache/%{ENV:SFC_PROTOCOL}/%{ENV:SFC_HOST}%{ENV:SFC_URI}%{ENV:SFC_FILE}%{ENV:SFC_EXT} -f + RewriteCond %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH} -f # NO frontend or backend user is logged in. Logged in users may see different # information than anonymous users. But the anonymous version is cached. So # don't show the anonymous version to logged in users. RewriteCond %{HTTP_COOKIE} !staticfilecache [NC] - # Uncomment the following line if you use MnoGoSearch - #RewriteCond %{HTTP:X-TYPO3-mnogosearch} ^$ - # We only redirect GET requests RewriteCond %{REQUEST_METHOD} GET # Rewrite the request to the static file. - RewriteRule .* %{ENV:SFC_ROOT}/typo3temp/tx_staticfilecache/%{ENV:SFC_PROTOCOL}/%{ENV:SFC_HOST}%{ENV:SFC_URI}%{ENV:SFC_FILE}%{ENV:SFC_EXT} [L] + RewriteRule .* %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH} [L] # Do not allow direct call the cache entries RewriteCond %{ENV:SFC_URI} ^/typo3temp/tx_staticfilecache/.* diff --git a/ext_conf_template.txt b/ext_conf_template.txt index 4fe6026be304..a4dc9905af4a 100755 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -28,7 +28,7 @@ htaccessTemplateName = EXT:staticfilecache/Resources/Private/Templates/Htaccess. # cat=basic; type=options[InsertPageIncache=InsertPageIncache,ContentPostProcOutput=ContentPostProcOutput,Eofe=Eofe]; label="InsertPageIncache" is the default. ContentPostProcOutput is later and EOFE is the latest. Please try to use the default hook. saveCacheHook = InsertPageIncache -# cat=generator; type=boolean; label=Disable Plain generator: When checked, the normal file will not write to the cache anymore. +# cat=generator; type=boolean; label=Enable Plain generator: When checked, the normal (default) file will write to the cache. enableGeneratorPlain = 1 # cat=generator; type=boolean; label=Enable GZIP compression generator: When checked, a gzipped version of the static file is written to the cache directory. Take care to also choose the proper .htaccess configuration when enabling this option. @@ -47,7 +47,7 @@ sendCacheControlHeaderRedirectAfterCacheTimeout = 0 sendTypo3Headers = 0 # cat=Headers; type=boolean; label=Send StaticFileCache header: If enabled: The .htaccess configuration send a "X-Cache: StaticFileCache" header, if the page is delivered via cache/.htaccess. You can use this option for debugging in e.g. json fiels (also html files) -sendStaticFileCacheHeader = 0 +sendStaticFileCacheHeader = 1 # cat=Cache Tags; type=boolean; label=Enable Cache Tags: Output the TSFE cache Tags for the current site in the rendering and for the cache entry cacheTagsEnable = 0