Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 如何让TYPO3对丢失的文件进行错误处理和重定向_.htaccess_Redirect_Typo3_Typo3 9.x_Typo3 10.x - Fatal编程技术网

.htaccess 如何让TYPO3对丢失的文件进行错误处理和重定向

.htaccess 如何让TYPO3对丢失的文件进行错误处理和重定向,.htaccess,redirect,typo3,typo3-9.x,typo3-10.x,.htaccess,Redirect,Typo3,Typo3 9.x,Typo3 10.x,默认情况下,htaccess会阻止对已知文件存储(如fileadmin目录)的重定向: RewriteRule (?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L] 但这也会阻止TYPO3错误处理和重定向模块在文件不存在时采取操作 我们的编辑希望为一些已删除的文件设置重定向,我想知道如果我不将fileadmin从重写规则中排除,是否会有任何负面影响 为什么这个规则默认存在 以下是完整的Type3默认重写,

默认情况下,htaccess会阻止对已知文件存储(如fileadmin目录)的重定向:

RewriteRule (?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
但这也会阻止TYPO3错误处理和重定向模块在文件不存在时采取操作

我们的编辑希望为一些已删除的文件设置重定向,我想知道如果我不将fileadmin从重写规则中排除,是否会有任何负面影响

为什么这个规则默认存在

以下是完整的Type3默认重写,以使上下文更容易理解:

但这也会阻止TYPO3错误处理和重定向模块在文件不存在时采取操作。 […] 为什么这个规则默认存在


看起来这里可能不需要这个规则;您是对的,在最后一条规则之前的not file/not folder检查将阻止这些文件夹中存在的任何内容被重写

我猜它只是用作一种“性能快捷方式”——在请求的URL上进行基本的正则表达式匹配比实际查询文件系统“是否存在”更便宜 因此,他们显然在此假设,在这些“特殊”文件夹中,不需要重写,它们只是数据存储


因此,是的,如果您希望Typo3也处理这些文件夹中的任何内容的404,那么您应该能够删除/注释掉此规则。

“为什么默认情况下会存在此规则?”-这样,fileadmin文件夹中的f.e.静态资产就可以由web服务器直接提供,而不必“通过管道传送”通过整个应用程序…?重写条件%{REQUEST_FILENAME}不是吗-f已经处理好了吗?是的,一般来说可以。当你一次只讲一行而没有适当的上下文时,我不知道剩下的应该是什么意思。对不起。我刚刚编辑了它并添加了完整的默认重写。看起来这个规则可能没有必要,你是对的,在最后一个规则之前的not file/not folder检查将阻止这些文件夹中存在的任何内容被重写。我猜它只是用作一种“性能快捷方式”——在请求的URL上进行字符串匹配比实际查询文件系统更便宜,这是否存在?所以,是的,如果你想让Typo3处理这些文件夹中的任何东西,那么你应该能够删除/注释掉这个规则。
<IfModule mod_rewrite.c>

# Enable URL rewriting
RewriteEngine On

# Store the current location in an environment variable CWD to use
# mod_rewrite in .htaccess files without knowing the RewriteBase
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*$ - [E=CWD:%2]

# Rules to set ApplicationContext based on hostname
#RewriteCond %{HTTP_HOST} ^dev\.example\.com$
#RewriteRule .? - [E=TYPO3_CONTEXT:Development]
#RewriteCond %{HTTP_HOST} ^staging\.example\.com$
#RewriteRule .? - [E=TYPO3_CONTEXT:Production/Staging]
#RewriteCond %{HTTP_HOST} ^www\.example\.com$
#RewriteRule .? - [E=TYPO3_CONTEXT:Production]

# Rule for versioned static files, configured through:
# - $GLOBALS['TYPO3_CONF_VARS']['BE']['versionNumberInFilename']
# - $GLOBALS['TYPO3_CONF_VARS']['FE']['versionNumberInFilename']
# IMPORTANT: This rule has to be the very first RewriteCond in order to work!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ %{ENV:CWD}$1.$3 [L]

# Access block for folders
RewriteRule _(?:recycler|temp)_/ - [F]
RewriteRule fileadmin/templates/.*\.(?:txt|ts)$ - [F]
RewriteRule ^(?:vendor|typo3_src|typo3temp/var) - [F]
RewriteRule (?:typo3conf/ext|typo3/sysext|typo3/ext)/[^/]+/(?:Configuration|Resources/Private|Tests?|Documentation|docs?)/ - [F]

# Block access to all hidden files and directories with the exception of
# the visible content from within the `/.well-known/` hidden directory (RFC 5785).
RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule (?:^|/)\. - [F]

# Stop rewrite processing, if we are in the typo3/ directory or any other known directory
# NOTE: Add your additional local storages here
RewriteRule ^(?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]

# If the file/symlink/directory does not exist => Redirect to index.php.
# For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]

</IfModule>
RewriteRule (?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]