Forum Moderators: phranque

Message Too Old, No Replies

Assistance with a rewrite rule

Having trouble getting a rule to work

         

mskanon

3:19 pm on Apr 8, 2006 (gmt 0)

10+ Year Member



Hello,

I am having trouble getting a rule to work and was hoping someone could help. I have two domain names pointing to the same IP, domain1.com and domain2.com. I want all calls to domain2.com to go to a specific page within domain1. The rule needs to work for domain2.com and www.domain2.com. I've seen examples that come close in this forum nothing that has worked for me yet. Here is what I have:

RewriteEngine on
RewriteCond %{HTTP_HOST} domain2.com$ [NC]
RewriteCond %{HTTP_HOST} www.domain2.com$ [NC]
RewriteRule ^(.*)$ /domain2.html [R=301,L]

Thanks for your help.

jdMorgan

12:04 am on Apr 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mskanon,

Welcome to WebmasterWorld!

You did not state whether you have *any* working rewriterules, so this may not apply. However, the first directive below is required to enable mod_rewrite on some servers -- those where this directive is not already present in the server configuration.

Eliminating the redundant second RewriteCond (your first one, having an unachored pattern, makes your second one redundant), and cleaning up a few minor points yields:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} domain2\.com [NC]
RewriteRule .* http://www.domain1.com/domain2.html [R=301,L]

This code must be placed somewhere where it will be executed when resources are requested from domain2 -- either in httpd.conf, conf.d, or in .htaccess in the top-level directive accessed by requests for domain2 resources.

Jim

mskanon

12:42 pm on Apr 9, 2006 (gmt 0)

10+ Year Member



Thanks Jim,

This worked perfectly. I am new to all of this and have a lot to learn. Thanks you to and the other in this forum for helping me and others out.

Michael