Many RewriteBase in one .htaccess file?

I come to this post when I am trying to find solution for a similar problem. It seems that there can be more then one base URL, but the logic does not stop after rewrite. If the URL hit both rewrite base, all the rewrite will be run. Therefore, the strictest rewrite base should be put at the end of the file. For this example, it should be:

RewriteEngine On

RewriteBase /
RewriteCond %{HTTP_HOST} domain.com
RewriteCond %{REQUEST_URI} !^/domain
RewriteCond %{REQUEST_URI} !^/cgi-bin
RewriteRule ^(.*)$ domain/$1 [L]

RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

Noticed that as both rewrite are being run, so if the rewrite contradicts, you will need to fall back to the accepted answer.


No, you can only have one base URL. Just rewrite your rules:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/. /blog/index.php [L]

RewriteCond %{HTTP_HOST} =example.com
RewriteCond %{REQUEST_URI} !^/domain
RewriteCond %{REQUEST_URI} !^/cgi-bin
RewriteRule ^(.*)$ domain/$1 [L]