[英]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.