Welcome to WebmasterWorld Guest from 54.145.144.101

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

302 redirect an entire folder to a message page

   
11:12 pm on Nov 3, 2013 (gmt 0)

10+ Year Member



How can I setup a 302 redirect of an entire folder to a message page in .htaccess? I already have the following code that redirects the non www version of the site to the www version. I want to do a 302 redirect for all the pages in www.example.com/special/ to www.exammple.com/message.html

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
11:14 pm on Nov 3, 2013 (gmt 0)

10+ Year Member



oops...sticky fingers on the "mm". I basically want to take a folder of my site offline until I'm able to fix things.
2:07 am on Nov 4, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



:: insert boilerplate about Why We Make You Do It Yourself ::

Oh, never mind, you've been around since 2002:

BEFORE your existing RewriteRule:

RewriteRule ^special http://www.example.com/message.html [R=302,L]


Here the R=302 is just a formality, since 302 (temporary) is the default value of [R], and the protocol-plus-domain makes your rewrite into a redirect regardless. But let's be precise about it.

That's assuming for the sake of discussion that you don't have a /dirname1/ or /dirnameblahblah/ that doesn't need redirecting. If you do, fine-tune the condition to

^special(/|$)


Otherwise you don't need a closing anchor, since you're not capturing. But as long as we're here: the optimal domain-name-canonicalization rule has a single condition that looks like this

!^(www\.example\.com)?$


"exactly www.example.com or exactly nothing". That will also get rid of any incoming requests with appended port number.

Psst! I don't know exactly how long the post-editing cutoff is, but I'm sure it's more than two minutes ;)
2:21 am on Nov 4, 2013 (gmt 0)

10+ Year Member



Thanks Lucy. I actually figured it out myself after many Google searches and testing. Panic adds that little bit of pressure to keep trying. :)

I put the code below in the folder's .htaccess file that I wanted to redirect. All pages return a 302 and my message page.

RewriteEngine on
RewriteRule ^.*$ /message.html [R=302,L]

Ta Da!
4:03 am on Nov 4, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I basically want to take a folder of my site offline until I'm able to fix things.

what you probably want is a 503 Unavailable response with a custom 503 error page specified for that directory that contains the message.html content.
2:49 pm on Nov 4, 2013 (gmt 0)

10+ Year Member



Thank you prhanque. That probably would have been a better solution. The problem was taken care of within a few hours. Hopefully, there won't be any fallout.
10:05 pm on Nov 4, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



the difference to a human visitor is almost zero.

if you were crawled during that time, you may find your /message.html content indexed for any pages that were crawled in that directory until they get recrawled and reindexed.

a 503 response avoids getting your "offline" message indexed.
10:25 pm on Nov 4, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



you may find your /message.html content indexed for any pages that were crawled in that directory until they get recrawled and reindexed.

I thought the difference between 301 and 302 was that 302 content doesn't get indexed at the old URL. No longer true? Or have I got it backward? Wouldn't be the first time :(
 

Featured Threads

Hot Threads This Week

Hot Threads This Month