title: Apache redirect all sub pages to home page except specific pages
body: <p>I have a site structure such as this:</p>
  
  <pre><code>www.domain.com
  www.domain.com/subpage-a
  www.domain.com/subpage-b
  www.domain.com/terms
  www.domain.com/request-information
  </code></pre>
  
  <p>I am trying to configure an Apache rewrite rule which will point <strong>all</strong> sub pages to the home page, bar specific pages.</p>
  
  <p>Using the example above I would need to redirect all the sub pages of the site to the home page, bar say the <code>terms</code> and <code>request-information</code> pages.</p>
  
  <p>I have been looking on StackOverflow and I've found a few questions that went unanswered, such as <a href="https://stackoverflow.com/questions/6326062/redirect-all-pages-except-one-page-to-sub-domain-htaccess">this one</a> and <a href="https://stackoverflow.com/questions/17543697/redirect-all-pages-to-top-level-page">this one</a>. The second link seems to kind of do what I want but I'm not sure how to override my rule for specific pages. </p>
  
  <h2>My configuration</h2>
  
  <p>Currently, my Apache file looks like this:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
   ServerName www.domain.co.uk
  
   ProxyPreserveHost On
   RewriteEngine On
   RewriteRule ^/(.*)$ http://server:8000/VirtualHostBase/http/%{HTTP_HOST}:80/root/site/VirtualHostRoot/$1 [L,P]
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost *:80&gt;
   ServerName domain.co.uk
   Redirect permanent / http://www.domain.co.uk/
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>In an attempt to get this working I appended this, just to see if I could get a sub page to redirect: </p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
   ServerName http://www.domain.co.uk/subpage-a
   Redirect permanent / http://www.domain.co.uk/
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>This didn't work but as there are a lot of sub pages to this site, I really would like more of a catch-all rule which would be ignored for certain sub pages. </p>
  
  <p>Is this possible and does anyone have any ideas? </p>
  
  <p>Thanks.</p>
  
  <h2>TL;DR</h2>
  
  <p>I'm looking for a 'catch-all' style Apache rewrite rule which will  redirect every subpage, bar certain pages to the home page of the domain.</p>
  
  <h2><strong>EDIT</strong>:</h2>
  
  <p>With regards to the answers below I have tried the following:</p>
  
  <h2>Answer #1</h2>
  
  <p>I modified my code to look like the following:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
   ServerName sub.domain.co.uk
  
   ProxyPreserveHost On
   RewriteEngine On
   RewriteCond %{REQUEST_URI} !^/(terms|request-information)(/.*|)$ [NC] 
   RewriteRule ^/(.*)$ http://server:8000/VirtualHostBase/http/%{HTTP_HOST}:80/root/site/VirtualHostRoot/$1 [L,P]
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost *:80&gt;
   ServerName domain.co.uk
   Redirect permanent / http://www.domain.co.uk/
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>However it seems to 404 the pages containing a dash, I can live with this however unfortunately it requires me to list all of the pages I would like to redirect in place of the <code>terms|request-information</code> above. </p>
  
  <h2>Answer #2</h2>
  
  <p>I must preserve the original re-write rule, multiple re-write rules seem to give me a "This website is not redirecting correctly" message in my browser, I did a copy-and-paste on this code amending the details as necessary but it resulted witg the error.</p>