.htaccess的维护模式允许某些目录 [英] Htaccess maintenance mode allow certain directories

查看:159
本文介绍了.htaccess的维护模式允许某些目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我用下面的逼我的网站进入维护模式,同时更新某些东西:

 #维护页转到
< IfModule mod_rewrite.c>
 RewriteEngine叙述上
 的RewriteCond%{REMOTE_ADDR}!^ 23 \ .1 \ 0.12 \ .167
 的RewriteCond%{REQUEST_URI}!/maintenance.html$ [NC]
 的RewriteCond%{REQUEST_URI} \(JPE G |?PNG | GIF)!。[NC]
 重写规则。* /maintenance.html [R = 302,L]
< / IfModule>
 

这一直运作良好,但现在我有,我想排除某些目录的被发送到maintenance.html和相当的情况时,在维护模式下让他们展示自己的正常内容。

因此​​,这将是这样的:

 根/
   的.htaccess
    maintenance.html
    的index.html
    everything.else.html
    / do_not_display_me
    / display_me_always
 

不知道这是可能要从根级的.htaccess或者如果我将不得不让狡猾与子DIR .htaccess文件,任何帮助是AP preciated。

解决方案

这应该做的工作。它告诉Apache将不会重新编写这些文件夹(这使得维护规则,省略了改写链将永远无法到达)。

 #激活重写引擎
RewriteEngine叙述上

#总是让这些文件夹
的RewriteCond%{REQUEST_URI} ^ / display_me_always [OR]
的RewriteCond%{REQUEST_URI} ^ / another_folder [OR]
的RewriteCond%{REQUEST_URI} ^ / even_more_folders
重写规则+  -  [L]

#维修规则
的RewriteCond%{REMOTE_ADDR}!^ 23 \ .1 \ 0.12 \ .167
的RewriteCond%{REQUEST_URI}!/maintenance.html$ [NC]
的RewriteCond%{REQUEST_URI} \(JPE G |?PNG | GIF)!。[NC]
重写规则。* /maintenance.html [R = 302,L]
 

  1. 在字母大小写的问题,因此,如果您需要匹配大小写混合拼写插入 NC, [OR]
  2. 您可以考虑在文件夹名称的末尾添加斜线 / 如果您在根文件夹中的文件具有相同的名称。

So I use the following for to force my site into maintenance mode while updating certain things:

# MAINTENANCE-PAGE REDIRECT
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REMOTE_ADDR} !^23\.1\.12\.167
 RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
 RewriteRule .* /maintenance.html [R=302,L]
</IfModule>

This has worked well, but now I have the situation when in maintenance mode that I wish to exclude certain dir's from being sent to the maintenance.html and rather have them display their normal contents.

So it would be something like:

root/
   .htaccess
    maintenance.html
    index.html
    everything.else.html
    /do_not_display_me
    /display_me_always

Not sure if this is possible from the root level .htaccess or if I'm going to have to get crafty with sub-dir .htaccess files, any help is appreciated.

解决方案

This should do the job. It tells Apache to not to rewrite those folders (which makes maintenance rules to be omitted as rewrite chain will never reach them).

# activate rewrite engine
RewriteEngine on

# always allow these folders
RewriteCond %{REQUEST_URI} ^/display_me_always [OR]
RewriteCond %{REQUEST_URI} ^/another_folder [OR]
RewriteCond %{REQUEST_URI} ^/even_more_folders
RewriteRule .+ - [L]

# maintenance rules
RewriteCond %{REMOTE_ADDR} !^23\.1\.12\.167
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=302,L]

  1. Letter case matters, so if you need to match mixed case spelling insert NC, into [OR].
  2. You may consider adding slash / at the end of folder names if you have files in root folder with the same names.

这篇关于.htaccess的维护模式允许某些目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆