Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess redirect using OR and NC

I would like to know if I can do this redirect where I have the domain: example.com be non case sensitive along with the or statement for the IP. Both work indpendently of each other but not together?

RewriteCond %{HTTP_HOST} ^example\.com [OR] [NC]
RewriteCond %{HTTP_HOST} ^123\.45\.67\.89
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
like image 406
Brian Barthold Avatar asked Aug 02 '11 20:08

Brian Barthold


People also ask

What is NC in htaccess?

Explanation of this .htaccess 301 redirect: The [NC] specifies that the http host is case insensitive. The escapes the "." - because this is a special character (normally, the dot (.) means that one character is unspecified). The final line describes the action that should be executed: RewriteRule ^(.*)$ http://www.

What is RewriteEngine on htaccess?

htaccess rewrite rule includes setting a combination of rewrite condition ( RewriteCond ) tests along with a corresponding rule ( RewriteRule ) if the prior conditions pass. In most cases, these rules should be placed at any point after the RewriteEngine on line in the . htaccess file located in the website's docroot.


1 Answers

Flags should be listed together separated by comma -- exactly the same way how it's done in RewriteRule itself:

RewriteCond %{HTTP_HOST} ^example\.com [OR,NC]
RewriteCond %{HTTP_HOST} ^123\.45\.67\.89
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Another approach:

RewriteCond %{HTTP_HOST} ^(example\.com|123\.45\.67\.89) [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
like image 106
LazyOne Avatar answered Sep 29 '22 12:09

LazyOne