[英]Apache2 htaccess multiple rules
我们为客户端构建了一个Web应用程序,当调用某些特定的url时应显示该应用程序。 所有其他URL应由现有的Typo3安装处理。 不幸的是,我们无权访问Apache2配置,因此我无法访问重写日志或更改VirtualHost定义。
.htaccess大致如下所示:
RewriteEngine On
# http://example.com/sub/foo/
RewriteCond %{REQUEST_URI} ^/sub/foo/.*
RewriteRule .* special.php [L]
# http://example.com/sub/bar/year/2014/
RewriteCond %{REQUEST_URI} ^/sub/bar/.*
RewriteRule .* special.php [L]
# Everything else should be typo3
RewriteRule .* general.php [L]
但是,所有调用都路由到general.php
文件。 根据此页面 ,.htaccess应该会按预期工作。 服务器是Apache 2.2。
有任何想法吗?
您需要从最后一条规则中排除special.php
。 规则1和规则2也可以像这样组合成一个:
RewriteEngine On
# http://example.com/sub/foo/
RewriteRule ^sub/(foo|bar)/ special.php [L,NC]
# Everything other than /special.php should be typo3
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule !^special\.php$ general.php [L,NC]
更新(Lars):解决方案是理解[L]
-flag的工作方式。 它会重新运行整个循环,因此每个重新发生的规则都必须以某种方式编写,以使已经重写的部分无效。 另外,从/sub/
目录中.htaccess
-file的视图(我将所有规则放到那里)中,第一个目录必须像这样被省略:
RewriteEngine On
# http://example.com/sub/foo/
RewriteRule ^(foo|bar)/ special.php [L,NC]
# Everything other than /special.php should be typo3
RewriteRule !^special\.php$ general.php [L,NC]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.