Skip to content

Commit 9c27ad1

Browse files
Fix: Resolve 404 errors on relative URLs
The .htaccess file was added to address 404 errors when navigating to relative URLs within the application.
1 parent 3fde985 commit 9c27ad1

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

public/.htaccess

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
# MIME types
23
<IfModule mod_mime.c>
34
AddType application/javascript .js
45
AddType text/css .css
@@ -17,15 +18,32 @@
1718
AddOutputFilterByType DEFLATE application/x-javascript
1819
</IfModule>
1920

20-
# Handle Angular and React Router
21+
# Handle React Router - Multiple fallback approaches
2122
<IfModule mod_rewrite.c>
2223
RewriteEngine On
2324

24-
# Handle requests for static files (images, css, js, etc.)
25+
# Handle requests for static files (don't redirect these)
2526
RewriteCond %{REQUEST_FILENAME} -f [OR]
2627
RewriteCond %{REQUEST_FILENAME} -d
2728
RewriteRule ^ - [L]
2829

30+
# Handle API calls (if any) - don't redirect these
31+
RewriteCond %{REQUEST_URI} ^/api/
32+
RewriteRule ^ - [L]
33+
2934
# For all other requests, serve index.html
30-
RewriteRule ^ /index.html [L]
35+
RewriteRule ^ index.html [L]
36+
</IfModule>
37+
38+
# Alternative fallback for servers that don't support mod_rewrite
39+
<IfModule !mod_rewrite.c>
40+
# Fallback: serve index.html for common SPA routes
41+
ErrorDocument 404 /index.html
42+
</IfModule>
43+
44+
# Security headers
45+
<IfModule mod_headers.c>
46+
Header always set X-Content-Type-Options nosniff
47+
Header always set X-Frame-Options DENY
48+
Header always set X-XSS-Protection "1; mode=block"
3149
</IfModule>

public/_redirects

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
# Redirects for Netlify and similar hosting providers
3+
/* /index.html 200

vercel.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
{
3+
"rewrites": [
4+
{
5+
"source": "/(.*)",
6+
"destination": "/index.html"
7+
}
8+
]
9+
}

0 commit comments

Comments
 (0)