Rewrite rule to redirect all subpages to a single page?

Posted by user784637 on Server Fault See other posts from Server Fault or by user784637
Published on 2012-06-19T08:11:03Z Indexed on 2012/06/19 9:18 UTC
Read the original article Hit count: 297

Filed under:
|

I have two two files /etc/apache2/sites-available/foo and /etc/apache2/sites-available/foo_maintenance

The rewrite rule I use in /etc/apache2/sites-available/foo is

<Directory /var/www/public_html>
        Options +FollowSymlinks
        RewriteOptions inherit
        RewriteEngine on
        #
        RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
        RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]
</Directory>

so that all mysite.com/* redirect to www.mysite.com

After I take my site down for maintenance, if the user is navigates to a subpage of the site like mysite.com/subdir/something.php I would like to redirect them to www.mysite.com so the index.html of the maintenance page would be displayed.

What is the rewrite rule to redirect all traffic from any subpage to www.mysite.com?

© Server Fault or respective owner

Related posts about apache2

Related posts about mod-rewrite