Options -Indexes
DirectorySlash Off

# Enforce HTTPS and the non-www canonical hostname.
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} !=on [OR]
  RewriteCond %{HTTP_HOST} ^www\.waveglass\.ca$ [NC]
  RewriteRule ^ https://waveglass.ca%{REQUEST_URI} [R=301,L,NE]
</IfModule>

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Remove trailing slashes from non-root URLs to match canonical tags.
  RewriteCond %{REQUEST_URI} .+/$
  RewriteRule ^(.+)/$ https://waveglass.ca/$1 [R=301,L,NE]

  # Old site blog -> Learning Center equivalents
  Redirect 301 /blog /learning-center
  Redirect 301 /blog/frameless-vs-semi-frameless-showers /learning-center/frameless-vs-semi-frameless-showers
  Redirect 301 /blog/ultimate-guide-frameless-glass-showers-bc /learning-center/ultimate-guide-frameless-glass-showers-bc

  # Old site /showers section -> Frameless Showers service page
  RedirectMatch 301 ^/showers/?$ /services/frameless-showers
  Redirect 301 /showers/fixed-panels-in-black-frame /services/frameless-showers
  Redirect 301 /showers/neo-angle-shower-with-header-and-pivot-hinges /services/frameless-showers
  Redirect 301 /showers/large-return-shower-with-double-bench-+-ceiling-support /services/frameless-showers
  Redirect 301 /showers/serenity-frameless-slider-kit /services/frameless-showers
  Redirect 301 /showers/inline-shower-with-header-support /services/frameless-showers

  # Old site /glass-shower-types section -> Frameless Showers service page
  Redirect 301 /glass-shower-types/steam-shower-with-movable-transom /services/frameless-showers
  Redirect 301 /glass-shower-types/framed-single-glass-door /services/frameless-showers
  Redirect 301 /glass-shower-types/fixed-panels-in-black-frame /services/frameless-showers
  Redirect 301 /glass-shower-types/fixed-panel-to-ceiling-(tub) /services/frameless-showers
  Redirect 301 /glass-shower-types/neo-angle-shower-with-header-and-pivot-hinges /services/frameless-showers
  Redirect 301 /glass-shower-types/floor-to-ceiling-fixed-panel-(angled-top) /services/frameless-showers
  Redirect 301 /glass-shower-types/frameless-neo-angle-with-glass-transom-support /services/frameless-showers

  # Old site /glass-doors section
  Redirect 301 /glass-doors/glass-doors-for-home-rec-room /services/commercial-glazing
  Redirect 301 /glass-doors/glass-sauna-and-steam-room-doors /portfolio/sauna-steam-room-doors
  Redirect 301 /glass-doors/office-glazed-glass-doors /services/commercial-glazing
  Redirect 301 /glass-doors/frosted-glass-bathroom-doors /services/frameless-showers
  Redirect 301 /glass-doors/frameless-glass-entry-doors /services/commercial-glazing

  # Old site /glass-shelve-types section -> Custom Mirrors / Glass Shelving
  RedirectMatch 301 ^/glass-shelve-types/?$ /services/custom-mirrors
  Redirect 301 /glass-shelve-types/floating-office-wall-shelves /portfolio/custom-glass-shelving
  Redirect 301 /glass-shelve-types/bar-nook-glass-shelves /portfolio/custom-glass-shelving
  Redirect 301 /glass-shelve-types/wall-mounted-curved-corner-shelves /portfolio/custom-glass-shelving
  Redirect 301 /glass-shelve-types/modern-cabinet-glass-display /portfolio/custom-glass-shelving
  Redirect 301 /glass-shelve-types/frameless-vanity-display-shelves /portfolio/custom-glass-shelving

  # Old site /glass-edge section -> Custom Mirrors
  Redirect 301 /glass-edge/polished-edge /services/custom-mirrors

  # Old site /glass-railings section (different structure from current)
  Redirect 301 /glass-railings/base-shoe-flush-mount /services/glass-railings
  Redirect 301 /glass-railings/stainless-post-with-handrail-insert /services/glass-railings
  Redirect 301 /glass-railings/base-mounted-channel-post-(aluminum) /services/glass-railings
  Redirect 301 /glass-railings-types/base-shoe-flush-mount /services/glass-railings

  # Old site /glass-partition-wall section -> Commercial Glazing
  Redirect 301 /glass-partition-wall/glass-office-partition-with-frosted-vinyl-design /services/commercial-glazing
  Redirect 301 /glass-partition-wall/custom-glass-divider-with-display-shelving /services/commercial-glazing

  # Old site /custom-glass-project section -> Portfolio
  Redirect 301 /custom-glass-project/retail-glass-counter-with-fabricated-posts /portfolio

  # Old site generic page renames
  RedirectMatch 301 ^/home/?$ /
  Redirect 301 /about-us /about
  RedirectMatch 301 ^/locations/?$ /services

  # 301 Redirects for deleted neighbourhood sub-pages -> parent city pages
  Redirect 301 /locations/brookswood /locations/langley
  Redirect 301 /locations/brookswood/custom-glass /locations/langley/custom-glass
  Redirect 301 /locations/brookswood/custom-mirrors /locations/langley/custom-mirrors
  Redirect 301 /locations/brookswood/frameless-showers /locations/langley/frameless-showers
  Redirect 301 /locations/brookswood/glass-railings /locations/langley/glass-railings
  Redirect 301 /locations/brookswood/residential-glass /locations/langley/residential-glass
  Redirect 301 /locations/brookswood/commercial-glazing /locations/langley/commercial-glazing
  Redirect 301 /locations/crescent-beach /locations/surrey
  Redirect 301 /locations/crescent-beach/custom-glass /locations/surrey/custom-glass
  Redirect 301 /locations/crescent-beach/custom-mirrors /locations/surrey/custom-mirrors
  Redirect 301 /locations/crescent-beach/frameless-showers /locations/surrey/frameless-showers
  Redirect 301 /locations/crescent-beach/glass-railings /locations/surrey/glass-railings
  Redirect 301 /locations/crescent-beach/residential-glass /locations/surrey/residential-glass
  Redirect 301 /locations/crescent-beach/commercial-glazing /locations/surrey/commercial-glazing
  Redirect 301 /locations/cypress-park /locations/north-vancouver
  Redirect 301 /locations/cypress-park/custom-glass /locations/north-vancouver/custom-glass
  Redirect 301 /locations/cypress-park/custom-mirrors /locations/north-vancouver/custom-mirrors
  Redirect 301 /locations/cypress-park/frameless-showers /locations/north-vancouver/frameless-showers
  Redirect 301 /locations/cypress-park/glass-railings /locations/north-vancouver/glass-railings
  Redirect 301 /locations/cypress-park/residential-glass /locations/north-vancouver/residential-glass
  Redirect 301 /locations/cypress-park/commercial-glazing /locations/north-vancouver/commercial-glazing
  Redirect 301 /locations/strawberry-hill /locations/surrey
  Redirect 301 /locations/strawberry-hill/custom-glass /locations/surrey/custom-glass
  Redirect 301 /locations/strawberry-hill/custom-mirrors /locations/surrey/custom-mirrors
  Redirect 301 /locations/strawberry-hill/frameless-showers /locations/surrey/frameless-showers
  Redirect 301 /locations/strawberry-hill/glass-railings /locations/surrey/glass-railings
  Redirect 301 /locations/strawberry-hill/residential-glass /locations/surrey/residential-glass
  Redirect 301 /locations/egmont /locations/vancouver
  Redirect 301 /locations/egmont/custom-glass /locations/vancouver/custom-glass
  Redirect 301 /locations/egmont/custom-mirrors /locations/vancouver/custom-mirrors
  Redirect 301 /locations/egmont/frameless-showers /locations/vancouver/frameless-showers
  Redirect 301 /locations/egmont/glass-railings /locations/vancouver/glass-railings
  Redirect 301 /locations/cambie /locations/vancouver
  Redirect 301 /locations/cambie/custom-glass /locations/vancouver/custom-glass
  Redirect 301 /locations/cambie/custom-mirrors /locations/vancouver/custom-mirrors
  Redirect 301 /locations/cambie/frameless-showers /locations/vancouver/frameless-showers
  Redirect 301 /locations/cambie/glass-railings /locations/vancouver/glass-railings

  # Redirect duplicate /commercial-glazing -> canonical service page
  RedirectMatch 301 ^/commercial-glazing/?$ /services/commercial-glazing

  # Serve prerendered directory pages at their slashless canonical URLs.
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^(.+)$ $1/index.html [END]

  # Send direct index-file requests to the directory URL.
  RewriteRule ^(.*/)?index\.html$ https://waveglass.ca/$1 [R=301,L,NE]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

# Caching for static assets
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType application/x-javascript "access plus 1 month"
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType font/woff "access plus 1 year"
</IfModule>

# Enable GZIP Compression
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml image/svg+xml
</IfModule>


# Performance & Security Headers
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
  Header set X-XSS-Protection "1; mode=block"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
  
  <FilesMatch "\.(webp|jpg|jpeg|png|gif|svg|ico)$">
    Header set Cache-Control "max-age=31536000, public, immutable"
  </FilesMatch>
  <FilesMatch "\.(woff2|woff|ttf)$">
    Header set Cache-Control "max-age=31536000, public, immutable"
  </FilesMatch>
  <FilesMatch "\.(js|css)$">
    Header set Cache-Control "max-age=2592000, public"
  </FilesMatch>
</IfModule>

