Baxil (baxil) wrote,

  • Location:
  • Mood:
  • Music:

Using mod_rewrite to take down a whole site

This is the product of half an hour of experimentation after research failed to provide a working answer. I hope it comes in useful for one of you someday. (n.b.: I also plan to bookmark it in my' web:repair category.)

Do you need to redirect everything on a web site to the same page? (This can happen if you need to notify all incoming web users of critical server problems and/or slashdotting that will force an extended outage; or if you want to make a Web site vanish. My current problem is the former.)

Put this code in the .htaccess file on the top level of your web directory. Change the two instances of "index.html" to the name of the page your message will be located at. Assuming mod_rewrite is installed and configured correctly, and the .htaccess file is readable by the web server, that should do the trick.

Options +FollowSymLinks

RewriteEngine on
RewriteBase /

# First, we want to define the items that are specifically excluded
# from our redirection.

# Play nice with search engines: let robots.txt go free.
RewriteRule ^robots.txt$ - [L]
# You can allow people through to other pages by using the same syntax:
# RewriteRule ^FULL_PATH/AND_PAGE.NAME$ - [L]

# In MOST cases, we want to allow CSS and image files through.
RewriteRule \.(css|jpe?g|gif|png)$ - [L]
# If you want to block people from getting images, however,
# comment out the above line and instead uncomment the
# next two -- that will cause images to return a 404 error.
# RewriteRule \.(css|jpe?g|gif|png)$ NAME_OF_A_NONEXISTENT_PAGE.html [L]
# RewriteRule ^NAME_OF_A_NONEXISTENT_PAGE\.html - [L]

# This is the important one: the name of the page that will contain
# your global message. By default, index.html in the top directory.
RewriteRule ^index\.html - [L]

# And this line throws everything we haven't excluded at it.
RewriteRule ^.*$ /index.html [L,R=302]

Currently, you can see the results of this by going to any page at Tomorrowlands. I'd rather have the site back up, but at least this is better than nothing.

(E-mail should work again too, btw. But the gmail address is probably safer for the moment.)
Tags: geekery, tlands

  • A filk three years in the making

    Oh hey! Had the source song come up for this one on Shuffle today, realized I never posted it, and further realized that the conversation which…

  • Don't say "ripoff." Say "homage."

    Geez, I thought I'd have recovered from my hiking trip faster than this. But I've been spending my weeknights readjusting my sleep schedule and my…

  • One final trail fling

    Not often I get to write a post from inside a sleeping bag at the top of a mountain. But lupagreenwolf convinced me to hit the trail one…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded