Forum Moderators: mack

Message Too Old, No Replies

.htaccess question

         

Scooter24

10:40 am on Oct 25, 2002 (gmt 0)

10+ Year Member Top Contributors Of The Month



I need to "shut down" my (non-commercial) site for a few days, as I'm already over my 20GB monthly traffic quota.

I was thinking of redirecting all requests from Mozilla agents to a page explaining that the site reopens on Nov 1st. This way Googlebot and the major search engines would still have access.

I tried this with .htaccess:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Mozilla
RewriteRule /*$ [mydomain.com...] [R,L]

But this caused the server to break down (maybe an endless loop) and I couldn't even access it via FTP for one or two hours.

For clarity I'm including the complete .htaccess file (well a shortened version actually):

-----------------------------------------------------------
<Files .htaccess>
order allow,deny
deny from all
</Files>

order allow,deny
allow from all
deny from 213.120.138
deny from ............ many denied IP numbers here

SetEnvIfNoCase User-Agent "Indy Library" getout
SetEnvIfNoCase User-Agent ^.*Demon getout
SetEnvIfNoCase User-Agent ....... long list with agents here

<Limit GET POST>
Order Allow,Deny
Allow from all
Deny from env=getout
</Limit>

Options -Indexes

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://216\.239.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://images\.google.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www\.google\..*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://babel\.altavista\..*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://world\.altavista\.com.*$ [NC]
RewriteRule \.(jpg¦JPG)$ [mydomain.com...] [R,L]

RewriteCond %{HTTP_USER_AGENT} ^Mozilla
RewriteRule /*$ [mydomain.com...] [R,L]

jdMorgan

2:48 pm on Oct 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Scooter24,

Yes, you need to take steps to prevent an infinite loop of redirection.

For a single "Come back soon" page and nothing else, you could use:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Mozilla.+
RewriteRule !^temp_closed\.htm$ temp_closed.htm$ [R,L]

Which reads, "If user-agent is Mozilla AND NOT requesting temp_closed, redirect to temp_closed."

If you need to display the page plus a few graphics and maybe include an external JavaScript, you could
use the form:

RewriteCond %{HTTP_USER_AGENT} ^Mozilla.+
RewriteCond %{REQUEST_URI} !^temp_closed\.htm$
RewriteCond %{REQUEST_URI} !^detour\.gif$
RewriteCond %{REQUEST_URI} !^beback\.js$
RewriteRule .* temp_closed\.htm [R,L]

The above is for per-directory .htaccess use. If you do this in httpd.conf, you'll need to add leading slashes to the paths.

Jim

<edit> typo </edit>

[edited by: jdMorgan at 4:03 pm (utc) on Oct. 25, 2002]

Longhaired Genius

4:00 pm on Oct 25, 2002 (gmt 0)

10+ Year Member



Are you sure you can't put a transfer limit on your site via the site control panel provided by your host?

Scooter24

7:22 pm on Oct 25, 2002 (gmt 0)

10+ Year Member Top Contributors Of The Month



Are you sure you can't put a transfer limit on your site via the site control panel provided by your host?

I wouldn't know how to do that. Not even sure my host offers such an option.

Scooter24

7:51 pm on Oct 25, 2002 (gmt 0)

10+ Year Member Top Contributors Of The Month



RewriteRule !^temp_closed\.htm$ temp_closed.htm$ [R,L]

Thanks - it worked for me when I changed the line to:

RewriteRule !^temp_closed\.htm$ [mydomain.com...] [R,L]

In other words I had to specify the full URL.

jdMorgan

1:31 am on Oct 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Scooter24,

RewriteRule !^temp_closed\.htm$ temp_closed.htm$ [R,L]

RewriteRule .* temp_closed\.htm [R,L]

Ack! Sorry - I should have fixed those typos, too! Glad you got it working...

RewriteRule .* /temp_closed\.htm [R,L]

RewriteRule !^temp_closed\.htm$ /temp_closed.htm$ [R,L]

(Forgot the leading slashes)

You shouldn't have to put the full "http://www.yoursite.com" in there unless you want an off-site redirect. Leaving it out makes your rules more portable in case you change domains or want to use them on another domain.

Jim