通过重定向为维护模式传递查询字符串


Passing a query string through redirect for maintenance mode

在使用维护模式系统时,我正在寻求一些指导,该系统在.htaccess文件中使用,通过mod_rewrite并传递$_GET

在正常情况下,在mod_rewrite中传递$_GET对我来说是完全可以的,但在这种情况下,我遇到了问题。。

我的维护系统代码如下:

RewriteCond                 %{REMOTE_HOST} !^XX'.XXX'.XXX'.XXX
RewriteCond                 %{REQUEST_URI} !/maintenance.php$ 
RewriteCond                 %{REQUEST_URI} !^/css/.*$
RewriteCond                 %{REQUEST_URI} !^/assets/.*$ 
RewriteRule ^$              maintenance.php [R=302,L]

因此,我需要的是能够将$_GET与rewriteRule一起传递,因此,当任何使用允许的IP的人将网站视为正常时,我可以定义该网站是在维护模式下查看的。

当然,不在允许的IP上的人会被重定向到maintenance.php文件,无论如何都不需要这个提醒,因为页面已经这样做了。

提前感谢任何能在这个问题上帮助我的人。

编辑::

# Start the mod re-write conditions #
RewriteRule ^([^/]+)'/$                         ?cat=generic&page=$1 [L]
RewriteRule ^products'/([^/]+)'/([^/]+)'/$      ?cat=product&page=$2 [L]
RewriteRule ^theteam'/([^/]+)'/$                ?cat=staff&page=$1 [L]

这就是我处理页面上其他链接的方式,我希望这就是你所需要看到的。

丹。

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !maintenance.php
RewriteCond %{REQUEST_URI} !(css|assets).*$
RewriteCond %{REMOTE_ADDR} !^XX'.XXX'.XXX'.XXX$
RewriteRule (.*) /maintenance.php [R=302,L]
RewriteCond %{REMOTE_ADDR} ^XX'.XXX'.XXX'.XXX$
RewriteRule (.*) $1?mode=maintenance [L,QSA]

这对我有效,首先你有否定重定向,所以无论谁试图在没有允许的IP的情况下访问,都会转到maintenance.php。

然后您有了append内部重定向,GET mode=maintenance将不可见,但会在那里。

您可以使用$_GET['mode']检索它。

如果您希望它直观地附加到查询字符串,并且仅附加到php文件,则可以使用:

RewriteCond %{REMOTE_ADDR} ^XX'.XXX'.XXX'.XXX$
RewriteCond %{REQUEST_FILENAME} '.php$
RewriteCond %{QUERY_STRING} !^mode=maintenance.*$
RewriteRule (.*) $1?mode=maintenance [R,L,QSA]

更新您的子目录格式的可见规则此规则应该放在它之前,如下所示:

RewriteCond %{REMOTE_ADDR} ^XX'.XXX'.XXX'.XXX$
RewriteCond %{QUERY_STRING} !.*mode=maintenance.*$
# for visible query string uncomment the below line and comment the next rule
#RewriteRule (.*) $1?mode=maintenance [R,L,QSA]
# for invisible query string
RewriteRule (.*) $1?mode=maintenance [L,QSA]
# Start the mod re-write conditions #
RewriteRule ^([^/]+)'/$                         ?cat=generic&page=$1 [L,QSA]
RewriteRule ^products'/([^/]+)'/([^/]+)'/$      ?cat=product&page=$2 [L,QSA]
RewriteRule ^theteam'/([^/]+)'/$                ?cat=staff&page=$1 [L,QSA]