homepage Welcome to WebmasterWorld Guest from 54.237.184.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
302 redirect an entire folder to a message page
nmjudy




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

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]

 

nmjudy




msg:4620916
 11:14 pm on Nov 3, 2013 (gmt 0)

oops...sticky fingers on the "mm". I basically want to take a folder of my site offline until I'm able to fix things.

lucy24




msg:4620933
 2:07 am on Nov 4, 2013 (gmt 0)

:: 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 ;)

nmjudy




msg:4620934
 2:21 am on Nov 4, 2013 (gmt 0)

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!

phranque




msg:4620942
 4:03 am on Nov 4, 2013 (gmt 0)

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.

nmjudy




msg:4621074
 2:49 pm on Nov 4, 2013 (gmt 0)

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.

phranque




msg:4621167
 10:05 pm on Nov 4, 2013 (gmt 0)

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.

lucy24




msg:4621176
 10:25 pm on Nov 4, 2013 (gmt 0)

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 :(

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved