Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine flags using RewriteCond?

I am using ISAPI-Rewrite on IIS7.
How can we combine [NC] and [OR] in a RewriteCond ? [NC,OR] ? What is the simple way to match domains with and without "www." ?

Here is a draft :

RewriteCond %{HTTP_HOST} ^old-one.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.old-one.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^old-two.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.old-two.com$ [NC]
RewriteRule ^(.*)$ http://www.new-website.com/$1 [QSA,L,R=301]
like image 849
Spilarix Avatar asked Dec 11 '25 16:12

Spilarix


1 Answers

Yes, [NC,OR] is the way of combining those two flags.

To combine multiple similar conditions into one, try this one:

RewriteCond %{HTTP_HOST} ^(old-one\.com|www\.old-one\.com|old-two\.com|www\.old-two\.com)$ [NC]
RewriteRule .* http://www.new-website.com%{REQUEST_URI} [L,R=301]

P.S. Since you are on IIS 7, why not use their native rewriting engine (URL Rewrite module) -- yes, it has different syntax (not .Apache's .htaccess, but standard web.config XML file) but does work fine (no performance issues here on my servers).

like image 55
LazyOne Avatar answered Dec 14 '25 14:12

LazyOne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!