0

A few questions:

  1. I have several domains hosted on the same server and I created some ReWrite rules that for specific {REQUEST_URI} gets redirected elsewhere. I copied these rules to each and every Virtual Host. Can I just put these rules in a file and do something like:

    <VirtualHost>

    ServerAdmin [email protected] DocumentRoot /var/www/html/<directory> ServerName <domain> ServerAlias www.<domain> ErrorLog logs/www_<domain>-error_log CustomLog logs/www_<domain>-access_log common RewriteEngine on Include rewrite_rules.conf 

  2. How can one create a rule that says if requests come in on specific domains to re-direct to a generic 'For Sale' page. Example, Same they type in www.Allertia.com and I want them to be directed to a For Sale Page.

2 Answers 2

2
  1. Yes, you can do that. The Include directive acts as if the contents of the named file were literally included.

  2. Assuming you want the same "for sale" page to show up for all of the domains:

    <VirtualHost *:80> ServerName forsale1.com ServerAlias www.forsale1.com ServerAlias forsale2.com ServerAlias www.forsale2.com ... RewriteEngine on RewriteRule .* /var/www/html/path/to/forsale.html </VirtualHost> 

    This will not change the URL that appears in the browser. If you want to perform an HTTP redirect so that the URL in the browser does change, you could add [R] after the rewrite rule. (Or you could use Redirect or RedirectMatch which might be a little quicker, if your server is under high load)

0

You want something that matches against the incoming HTTP Host: header, so a rule such as this will work:

RewriteCond %{http_host} !^www.allertia.com RewriteRule / http://example.com/for-sale.html [R,L] 

The issue you'll find is that if you say "Rewrite all requests for http://www.alertia.com to http://alertia.com/for-sale.html" you'll get a redirection loop. So redirecting to an un-related domain is simplest.

However if you wish you can create a rule which says "For all requests not equal to /for-sale.html, do the rewrite":

RewriteCond %{http_host} www.allertia.com RewriteRule !/for-sale.html$ http://www.allertia.com/for-sale.html [R,L] 

Obviously you'll need to update the path for the "for sale" page. You'll probably also want to include the rules twice:

12
  • @Steve Kemp - Do I need to create a Virtual Host for Allertia to achieve this or is there a generic way to have ReWrite rules evaluated and acted upon at a non Virtual Host level? I have a number of domains for sale and if I can avoid creating a Virtual Host for each one that would be best! Commented Apr 17, 2011 at 21:46
  • I was working on the assumption these rules were global - so you didn't need to create a virtual host for them. Commented Apr 17, 2011 at 21:49
  • @Steve - Oh, sorry, where do global rules go in httpd.conf? Commented Apr 17, 2011 at 22:00
  • Add the rules I suggested to your "rewrite_rules.conf" file - the one you demonstrate using already in your config. Commented Apr 17, 2011 at 22:37
  • @Steve oh, #1 has nothing to do with #2 above. They are different questions. I don't understand where to put/how to use ReWrite rules without creating a virtual host for each domain. Can you explain? Commented Apr 17, 2011 at 22:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.