# =====================================================================
#  .htaccess for public_html on heroonline.org — LAUNCH DAY
#  Copy this file to public_html/.htaccess on the heroonline.org account
#  (replacing the WordPress one). Every URL Google currently knows on the
#  old WordPress site gets a permanent (301) redirect to its new page, so
#  existing rankings and backlinks carry over instead of turning into 404s.
# =====================================================================

Options -Indexes
RewriteEngine On

# --- force https + no-www (pick ONE hostname and stick with it) ---------
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://heroonline.org%{REQUEST_URI} [L,R=301,NE]

# --- protect the contact-form internals ---------------------------------
RewriteRule ^inc/ - [F,L]

# --- old WordPress PAGES → new pages --------------------------------------
# (NE keeps the #fragment intact; browsers honour it in a redirect)
RewriteRule ^about-us/?$                     /about.html                 [R=301,L]
RewriteRule ^contact/?$                      /contact.html               [R=301,L]
RewriteRule ^donate/?$                       /donate.html                [R=301,L]
RewriteRule ^privacy-policy/?$               /about.html#privacy         [R=301,L,NE]
RewriteRule ^terms-and-conditions/?$         /about.html#terms           [R=301,L,NE]
RewriteRule ^docktown-marina/?$              /marine-justice.html        [R=301,L]
RewriteRule ^hero-library/?$                 /hero-hub.html              [R=301,L]
RewriteRule ^in-the-news/?$                  /hero-hub.html              [R=301,L]
RewriteRule ^resources-for-students/?$       /student-hub.html           [R=301,L]
# board & staff bio pages → board section
RewriteRule ^(kathleen-harris|benjamin-labrot-md|carmen-and-lazare|dr-adam-wymore|joshua-a-lipp|rich-wallace|dr-daniel-medina)/?$  /about.html#board  [R=301,L,NE]

# --- old WordPress POSTS → the same story in the HERO Hub -----------------
RewriteRule ^environmental-law-climate-change/?$   /hero-hub.html#environmental-law-climate-change   [R=301,L,NE]
RewriteRule ^clean-up-day/?$                       /marine-justice.html#cleanup                       [R=301,L,NE]
RewriteRule ^redwood-city-and-hannig-environmental-research-organization-settle-litigation.*$  /marine-justice.html#settlement  [R=301,L,NE]
RewriteRule ^why-is-the-smithsonian-in-panama/?$   /hero-hub.html#why-is-the-smithsonian-in-panama   [R=301,L,NE]
RewriteRule ^end-of-eternal-ice.*$                 /hero-hub.html#end-of-eternal-ice                 [R=301,L,NE]
RewriteRule ^the-where-when-and-why-of-bringing-back-kelp/?$  /hero-hub.html#bringing-back-kelp     [R=301,L,NE]
RewriteRule ^how-data-science-can-help-fight-climate-change/?$  /hero-hub.html#data-science-climate [R=301,L,NE]
RewriteRule ^hanning-enviromental-research_organization/?$  /hero-hub.html#class-notes-mit          [R=301,L,NE]
RewriteRule ^zeva-gerochi/?$                       /student-hub.html#submissions                     [R=301,L,NE]
RewriteRule ^ariana-vega-garcia/?$                 /student-hub.html#submissions                     [R=301,L,NE]
RewriteRule ^ocean-acidification-and-reefs/?$      /hero-hub.html#ocean-acidification-and-reefs      [R=301,L,NE]
RewriteRule ^museum-of-idaho-jan-2024/?$           /hero-hub.html#museum-of-idaho                    [R=301,L,NE]
RewriteRule ^red-frogs-of-bocas/?$                 /hero-hub.html#red-frogs-of-bocas                 [R=301,L,NE]
RewriteRule ^inside-the-smithsonians-tropical-forest-lab/?$  /hero-hub.html#inside-the-smithsonians-tropical-forest-lab  [R=301,L,NE]
RewriteRule ^aquatic-pollutants-in-oceans-and-fisheries/?$   /hero-hub.html#aquatic-pollutants       [R=301,L,NE]
RewriteRule ^climate-change-causes-effects-and-predictions/?$  /hero-hub.html#climate-change-causes-effects  [R=301,L,NE]
RewriteRule ^redwood-city-faces-fresh-lawsuit-over-floating-homes-at-docktown-marina/?$  /marine-justice.html#record  [R=301,L,NE]
RewriteRule ^redwood-city-faces-suit-over-docktown-marina/?$  /marine-justice.html#record             [R=301,L,NE]
RewriteRule ^city-council-oks-docktown-deal.*$     /marine-justice.html#record                       [R=301,L,NE]
RewriteRule ^kelp-kids-environmental-lesson-plans/?$  /student-hub.html#resources                    [R=301,L,NE]

# --- pages from the September 5 build that no longer exist ---------------
RewriteRule ^(our-work|climate|maritime-practices|dolphins|vessels|panama)\.html$  /river-to-reef.html  [R=301,L]
RewriteRule ^(educators|teachers|students|take-action)\.html$  /student-hub.html  [R=301,L]
RewriteRule ^news\.html$                            /hero-hub.html              [R=301,L]
RewriteRule ^river-2-reef\.html$                    /river-to-reef.html         [R=301,L]

# --- WordPress archives, feeds, authors, pagination ----------------------
RewriteRule ^category/redwood-city-docktown-marina/?$  /marine-justice.html        [R=301,L]
RewriteRule ^category/.*$                              /hero-hub.html              [R=301,L]
RewriteRule ^tag/.*$                                   /hero-hub.html              [R=301,L]
RewriteRule ^author/.*$                                /about.html#board           [R=301,L,NE]
RewriteRule ^page/[0-9]+/?$                            /hero-hub.html              [R=301,L]
RewriteRule ^(feed|comments/feed)/?$                   /hero-hub.html              [R=301,L]
RewriteRule ^wp-(login|admin|json)(/.*)?$              /                           [R=301,L]

# --- friendly URLs for the new site: /about → /about.html -----------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([a-z0-9-]+)/?$ /$1.html [L]

# (No ErrorDocument → index: a real 404 is better for Google than a "soft 404".)
