简体   繁体   中英

Apache2 htaccess multiple rules

We've built a web application for a client, which should be shown when some specific urls are called. All other urls should be handled by the existing Typo3 installation. Unfortunately, we do not have access to the Apache2 configuration, so I cannot access the rewrite log or change the VirtualHost definition.

The .htaccess looks approximately like this:

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. According to this page , the .htaccess should work as expected. Server is an Apache 2.2.

Any ideas?

You need to exclude special.php from last rule. Also rule 1 and rule 2 can be combined into one like this:

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. 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:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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