WebFaction
Community site: login faq

My client has two domains they want to point at a specific page on their site, but my current httpd.conf changes don't seem to be working. They look like this:

RewriteCond %{HTTP_HOST} ^www\.domain\.org
RewriteCond %{HTTP_HOST} ^www\.domain\.net
RewriteRule ^$ /new-page/ [L]

asked 07 Mar '13, 10:31

tclancy
861515
accept rate: 6%


This wasn't quite what I needed, because of what I used as an example for cut and paste (but the OR piece was key). Here's what did work:

RewriteCond %{HTTP_HOST} (.+\.)?domain\.org [OR]
RewriteCond %{HTTP_HOST} (.+\.)?domain\.net
RewriteCond %{REQUEST_URI} !=/landing-page/
RewriteRule ^.+$ /landing-page/ [L,R=301]

The third line is key because you wind up with a loop otherwise. I had the wrong regex on the ^www. because I want any subdomain (or none at all) to redirect.

permanent link

answered 07 Mar '13, 19:51

tclancy
861515
accept rate: 6%

Hello,

The code that you mentioned above will never work because those two RewriteCond statements use "AND" logic. In other words, that RewrieRule will only be executed if HTTP_HOST is www.domain.org, AND HTTP_HOST is www.domain.net... which, of course, can never happen.

You can fix your rules by using an [OR] flag:

RewriteCond %{HTTP_HOST} ^www\.domain\.org$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.net$
RewriteRule ^$ /new-page/ [L]

You also could have fixed this by using a single RewriteCond with a modified regular expression:

RewriteCond %{HTTP_HOST} ^www\.domain\..+$
RewriteRule ^$ /new-page/ [L]
permanent link

answered 07 Mar '13, 14:50

likebike
3366
accept rate: 28%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×225
×30
×2

question asked: 07 Mar '13, 10:31

question was seen: 2,330 times

last updated: 07 Mar '13, 19:51

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM