Question : Apache RewriteEngine - redirect home page & alternate domain

Hello all,

Can you help me write a rewrite file?  Here's what I need:

Whether a user surfs to the website homepage using www.domain.com or www.domains.com (note the extra 's'), they are redirected to www.domains.com/cgi-bin/myscript.pl

If they try to go directly to www.domain.com/cgi-bin/myscript.pl (note, no 's'), they still get redirected to www.domains.com/cgi-bin/myscript.pl

I tried this:

RewriteEngine On
RewriteCond %{HTTP_HOST} =www.domain.com [NC,OR]
RewriteCond %{HTTP_HOST} =www.domains.com [NC]
RewriteRule ^(.*)$ http://www.domains.com/cgi-bin/myscript.pl [R,L]

but that seems to set up an infinite loop.

Thanks.

Answer : Apache RewriteEngine - redirect home page & alternate domain

Go easy, and do it in two steps

#redirect from domain to domains
RewriteCond %{HTTP_HOST} =www\.domain\.com [NC]
RewriteRule .* http://www.domains.com%{REQUEST_URI} [L,R=301]

#and now to cgi-bin/myscript.pl, unless it already cgi-bin/myscript.pl
RewriteCond %{REQUEST_URI} !cgi-bin/myscript.pl
RewriteRule .* http://www.domains.com/cgi-bin/myscript.pl [L,R=301]
Random Solutions  
 
programming4us programming4us