Using mod_rewrite to take down a whole site - Baxil [bakh-HEEL'], n. — LiveJournal
? ?
Baxil [bakh-HEEL'], n. My Sites [Tomorrowlands] [The TTU Wiki] [Photos]
View My LJ [By Tag]

November 12th, 2007
07:35 pm
[User Picture]


Previous Entry Share Flag Next Entry
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.)

Current Location: ~spiral
Current Mood: draineddrained
Current Music: George Winston, "Longing/Love"
Tags: ,

(2 comments | Leave a comment)

[User Picture]
Date:November 13th, 2007 05:29 am (UTC)
Bah. And just earlier today did I recommend a friend check out Tlands - because he explained to me a long and drawn out (and almost nightmarish) dream he had of all the members of a mostly werewolf forum turned into their true forms, the gov't doing the things the gov't does and the military doing the things the military does. Long story short: big werewolf forum, lots of werewolves, mayhap a dragon, and a were-hare.
[User Picture]
Date:November 13th, 2007 06:39 am (UTC)
Well, still, better the "Try Again Soon" message than a mysterious server outage.

Latest word from Inaki is that new hosting arrangements have been produced and the servers are being installed in the racks tonight. From here I wouldn't be surprised if we're back to full operation in 48 hours. Worse comes to worse, I do still have the site backup from eight hours before the crash.
Tomorrowlands Powered by