.htaccess Rewrite problems .htaccess Rewrite problems apache apache

.htaccess Rewrite problems


RewriteCond is only applicable to the very next RewriteRule. So yes in your case you will need a RewriteCond preceeding each and every RewriteRule.

But good news is that it can be avoided.

If you want to avoid writing these multiple RewriteCond you can do so as this code:

## If the request is for a valid directoryRewriteCond %{REQUEST_FILENAME} -d [OR]## If the request is for a valid fileRewriteCond %{REQUEST_FILENAME} -f [OR]## If the request is for a valid linkRewriteCond %{REQUEST_FILENAME} -l## don't do anythingRewriteRule ^ - [L]RewriteRule ^(img/.*)$ http://old.site.com/$1 [L,R=301]RewriteRule .* index.php [L]


Yes.

You can't have two RewriteRules based on one (set of) RewriteConds.

Some quotes from the manual:

Each rule can have an unlimited number of attached rule conditions...

One or more RewriteCond can precede a RewriteRule directive...

The RewriteRule directive [...] can occur more than once, with each instance defining a single rewrite rule...