Forum Moderators: phranque

Message Too Old, No Replies

two redirects

redirecting from IP and non-www

         

eveningwalk

9:30 am on Dec 20, 2005 (gmt 0)

10+ Year Member



I'm trying to do two redirects:
1. From IP address to www and
2. From non-www to www

Here is what I have for the first part:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^11\.222\.33\.444
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

What do I add for the non-www to www redirect?

Thanks,
ew

jdMorgan

2:44 pm on Dec 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just 'OR' it in:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^11\.222\.33\.444 [OR]
RewriteCOnd %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Jim

eveningwalk

8:28 pm on Dec 20, 2005 (gmt 0)

10+ Year Member



Thanks Jim. Now I have another site which requires only a non-www to www redirect. I assume the following will work:

RewriteEngine on
RewriteCOnd %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

And is [NC] in the second line required too?

Thanks,
ew

jdMorgan

2:51 am on Dec 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[NC] is required only where it is already shown in the code in this thread.

I'd suggest you test the code, rather than asking here... There are so many differences between servers that only testing in your environment will give a proper answer.

Jim