-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.htaccess
More file actions
69 lines (56 loc) · 2.81 KB
/
Copy path.htaccess
File metadata and controls
69 lines (56 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# SEO: consolidate the www version to non-www (fixes the homepage being split across two URLs in Google)
RewriteCond %{HTTP_HOST} ^www\.transformpersonaltraining\.com [NC]
RewriteRule ^(.*)$ https://transformpersonaltraining.com/$1 [R=301,L]
# SEO: rescue old URLs that still rank in Google but changed slug during the migration
RewriteRule ^healthy-restaurants-in-chicago/?$ /blog/the-top-7-healthy-restaurants-in-chicago/ [R=301,L]
RewriteRule ^stop-the-insanity/?$ /blog/ [R=301,L]
# SEO: 301-redirect old root-level blog URLs to their new /blog/ location (only when that page actually exists)
RewriteCond %{REQUEST_URI} !^/blog/
RewriteCond %{REQUEST_URI} !^/dist/
RewriteCond %{DOCUMENT_ROOT}/dist/blog/$1/index.html -f
RewriteRule ^([a-z0-9-]+)/?$ /blog/$1/ [R=301,L]
# 1. Redirect /dist/foo to /foo (Remove /dist prefix if visible)
RewriteCond %{THE_REQUEST} \s/dist/ [NC]
RewriteRule ^dist/(.*)$ /$1 [R=301,L]
# 2. Add trailing slash to directories (Prevent mod_dir exposing /dist)
# If request doesn't end in slash, and it exists as a directory in /dist
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{DOCUMENT_ROOT}/dist/$1 -d
RewriteRule ^(.*)$ /$1/ [R=301,L]
# 3. Serve root from dist/index.html
RewriteRule ^$ dist/index.html [L]
# 4. Rewrite everything else to /dist/ folder internally
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/dist/
RewriteRule ^(.*)$ /dist/$1 [L]
</IfModule>
# Serve the branded 404 page (built by Astro) instead of the hosting default
ErrorDocument 404 /dist/404.html
<IfModule mod_headers.c>
# HSTS: tell browsers to always use HTTPS (site is fully HTTPS already)
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
# Pages must always be served fresh. The hosting server's cache was
# serving days-old copies of pages (blank forms, outdated content) even
# after dashboard cache clears. no-cache means: always re-check with the
# origin before serving. Static assets keep their long cache rules below.
<FilesMatch "\.html$">
Header set Cache-Control "no-cache, must-revalidate"
Header set X-LiteSpeed-Cache-Control "no-cache"
</FilesMatch>
# Site stylesheets/scripts without content hashes (e.g. /styles/*.css): 7 days
<FilesMatch "\.(css|js)$">
Header set Cache-Control "public, max-age=604800"
</FilesMatch>
# Astro's content-hashed assets (filename changes when content changes) can be cached forever
<FilesMatch "\.[A-Za-z0-9_-]{8}\.(css|js)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
# Images and icons: 30 days
<FilesMatch "\.(webp|png|jpe?g|gif|ico|svg)$">
Header set Cache-Control "public, max-age=2592000"
</FilesMatch>
</IfModule>