简体   繁体   English

为什么我的.htaccess文件无法正确重定向?

[英]Why doesn't my .htaccess file redirect properly?

This is my code: 这是我的代码:

Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"

RewriteEngine on
RewriteCond %{REQUEST_URI} !(admin)
RewriteRule !maintenance\.php$ /maintenance.php [R=301,L]

I want to redirect all traffic on the site to maintenance.php except for any requests for files in /admin. 我想将网站上的所有流量都重定向到maintenance.php,但对/ admin中文件的任何请求除外。 I've tried so many combinations that never work. 我已经尝试了很多组合,但这些组合永远都无效。 It always redirects no matter what. 无论如何,它总是重定向。 I can't figure out what could be causing this. 我不知道是什么原因造成的。

UPDATE: I figured something out. 更新:我想通了一些东西。 If I comment out the .htaccess in the admin folder, Ben's code works. 如果我将admin文件夹中的.htaccess注释掉,则Ben的代码有效。 Here's the code there: 这里是代码:

AuthType Basic
AuthName "Restricted area"
AuthUserFile "/home1/user/.htpasswds/public_html/example/admin/passwd"
require valid-user

What can I do to this .htaccess file to allow it to work? 我可以对这个.htaccess文件做些什么才能使其工作?

Don't use permanent redirect R=301 in this purpose, you site is not maintenance permanently. 不要为此目的使用永久重定向R=301 ,因为您的网站不是永久维护的站点。 Use temporary redirect R=302 only, otherwise your users will always see maintenance page even if you remove this rule, because R=301 is cached by browser. 仅使用临时重定向R=302 ,否则即使您删除此规则,您的用户也将始终看到维护页面,因为R=301被浏览器缓存。

%{REQUEST_URI} starts with / . %{REQUEST_URI}/开头。

RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{REQUEST_URI} !^/maintenance.php$
RewriteRule ^ /maintenance.php [R=302,L]

why don't you use this line DirectoryIndex maintenance.php in .htaccess in order to redirect to this page . 为什么不在.htaccess中使用此行DirectoryIndex maintenance.php来重定向到此页面。 ones your site is ready you can remove maintenance mode by commenting the above line 您的网站已经准备好了,您可以通过注释上面的行来删除维护模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM