如何允许某些特定URL和其他URL将重定向到维护页面

时间:2013-10-21 10:41:26

标签: .htaccess

我的htaccess文件存在问题..

http://www.example.com/customer/contract/download
http://www.example.come/customer/contract/upload

以上网址应该有效,其他网址应该重定向到maintenance.html。

如何在我的htaccess文件中定义这些案例?

这是我的htaccess代码..

RewriteEngine on
IndexIgnore *

RewriteCond $1 !^(index\.php|public|images|robots\.txt|favicon\.ico|redirigir\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule ^(.*)$ public/maintenance.html [L]

2 个答案:

答案 0 :(得分:0)

首先,您有两行捕获所有网址并具有[L] last标记。您的第二个RewriteRule仅对第一个RewriteCond中配置的例外情况起作用。你需要改变这样才能让你的第二个RewriteRule发挥作用:

RewriteCond $1 !^(index\.php|public|images|robots\.txt|favicon\.ico|redirigir\.php)
RewriteRule ^(.*)$ public/maintenance.html [L]

然后将您的例外URL添加到.htaccess文件中。

如果它们是有效目录,您只需添加一行即可排除所有目录。您需要添加[OR]标志,这意味着RewriteCond必须为true。如果没有此标志,则只有在两个条件都适用时才会匹配规则。

RewriteCond $1 !^(index\.php|public|images|robots\.txt|favicon\.ico|redirigir\.php) [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/maintenance.html [L]

如果通过第一个重写规则重写它们,则必须在第一个规则上添加另一个条件:

RewriteCond $1 !^(index\.php|public|images|robots\.txt|favicon\.ico|redirigir\.php)
RewriteCond $1 customer/contract/(download|upload)
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteRule ^(.*)$ public/maintenance.html [L]

此处第一条规则仅匹配您的特殊网址,第二条规则将匹配其他所有网址。

答案 1 :(得分:0)

以下规则适合您:

RewriteEngine on
IndexIgnore *

RewriteCond $1 !^(index\.php|public|images|robots\.txt|favicon\.ico|redirigir\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond $1 !^(index\.php|public|images|robots\.txt|favicon\.ico|redirigir\.php|customer)
RewriteRule ^(.*)$ public/maintenance.html [L]
相关问题