简体   繁体   English

Apache2 htaccess多个规则

[英]Apache2 htaccess multiple rules

We've built a web application for a client, which should be shown when some specific urls are called. 我们为客户端构建了一个Web应用程序,当调用某些特定的url时应显示该应用程序。 All other urls should be handled by the existing Typo3 installation. 所有其他URL应由现有的Typo3安装处理。 Unfortunately, we do not have access to the Apache2 configuration, so I cannot access the rewrite log or change the VirtualHost definition. 不幸的是,我们无权访问Apache2配置,因此我无法访问重写日志或更改VirtualHost定义。

The .htaccess looks approximately like this: .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]

However, all calls are routed to the general.php file. 但是,所有调用都路由到general.php文件。 According to this page , the .htaccess should work as expected. 根据此页面 ,.htaccess应该会按预期工作。 Server is an Apache 2.2. 服务器是Apache 2.2。

Any ideas? 有任何想法吗?

You need to exclude special.php from last rule. 您需要从最后一条规则中排除special.php Also rule 1 and rule 2 can be combined into one like this: 规则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]

Update (Lars): Solution was the understanding of how the [L] -flag works. 更新(Lars):解决方案是理解[L] -flag的工作方式。 It re-runs the whole loop, so every reoccuring rule has to be written in a way, that it negates the already rewritten parts. 它会重新运行整个循环,因此每个重新发生的规则都必须以某种方式编写,以使已经重写的部分无效。 Also, from the view of the .htaccess -file in the /sub/ -directory, where I put all the rules, the first directory has to be omitted like so: 另外,从/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.

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