I simply want to skip a redirect done with a "RewriteRule" when a specific env variable is not set by a former "RewriteRule".
当前一个“RewriteRule”没有设置特定的env变量时,我只想跳过使用“RewriteRule”完成的重定向。
Here is my example which doesn't work.
这是我的例子,它不起作用。
RewriteEngine on
RewriteBase /
#
# if /internal ... set ENV var INTERNALAREA = true
#
RewriteRule ^internal(.*)$ - [E=INTERNALAREA:true]
#
# Redirect to /maintenance.php if not in internal area and not already at /maintenance.php
#
RewriteCond %{ENV:INTERNALAREA} !true
RewriteCond %{REQUEST_URI} !^/maintenance.php$
RewriteRule ^(.*)$ /maintenance.php [R=302,L]
#
# Default TYPO3 rewrites
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]
RewriteRule ^fileadmin/(.*/)?_recycler_/ - [F]
RewriteRule ^fileadmin/templates/.*(\.txt|\.ts)$ - [F]
RewriteRule ^typo3conf/ext/[^/]+/Resources/Private/ - [F]
RewriteRule ^(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
In the maintenance PHP I have a phpinfo()
which outputs $_SERVER['REDIRECT_REDIRECT_INTERNALAREA'] = true
.
在维护PHP我有一个phpinfo()输出$ _SERVER ['REDIRECT_REDIRECT_INTERNALAREA'] =真。
I'm always getting redirected to the maintenance.php
when accessing /internal/...
.
访问/ internal /时,我总是被重定向到maintenance.php。
What am I doing wrong?
我究竟做错了什么?
1 个解决方案
#1
6
I have found the answer to my question. The problem has its roots at the following question:
我找到了问题的答案。问题源于以下问题:
在Apache RewriteRule指令中设置环境变量时,是什么原因导致变量名称以“REDIRECT_”作为前缀?
When now setting the following before all the other rules everything does work as expected:
现在,在所有其他规则之前设置以下内容时,一切都按预期工作:
RewriteCond %{ENV:REDIRECT_INTERNALAREA} (.+)
RewriteRule .* - [E=INTERNALAREA:%1]
Here is how it works. It checks on every run if the prefixed env var is already set and re adds the environment variable without the REDIRECT_
prefix.
下面是它的工作原理。如果已经设置了带前缀的env var,它会检查每次运行,并重新添加没有REDIRECT_前缀的环境变量。
#1
6
I have found the answer to my question. The problem has its roots at the following question:
我找到了问题的答案。问题源于以下问题:
在Apache RewriteRule指令中设置环境变量时,是什么原因导致变量名称以“REDIRECT_”作为前缀?
When now setting the following before all the other rules everything does work as expected:
现在,在所有其他规则之前设置以下内容时,一切都按预期工作:
RewriteCond %{ENV:REDIRECT_INTERNALAREA} (.+)
RewriteRule .* - [E=INTERNALAREA:%1]
Here is how it works. It checks on every run if the prefixed env var is already set and re adds the environment variable without the REDIRECT_
prefix.
下面是它的工作原理。如果已经设置了带前缀的env var,它会检查每次运行,并重新添加没有REDIRECT_前缀的环境变量。