Alex Ibrahim Ojea
Alex Ibrahim Ojea

Reputation: 107

Angular app not retrieving localStorage/sessionStorage on deep links with current production .htaccess configuration

I'm working on an Angular 18 application that uses localStorage and sessionStorage to store user data. Everything works fine when I access the site using the root URL, like https://www.example.com/. However, when I access a deep link directly, such as https://www.example.com/specificSubRoute/anID, the localStorage and sessionStorage appear to be empty.

This issue does not happen when I'm running the application locally; it only occurs in the production environment hosted in a 1&1 ASP.NET server solution.

When accessing deep links directly, localStorage and sessionStorage do not retain the data set during the initial load at the root URL. This leads to issues in my application where user-specific data is missing or not loaded correctly.

I'm assuming that my issue has to do with the .htaccess or the server configuration since it only happens in production.

My .htaccess configuration in production:

RewriteEngine On
RewriteBase /

# Redirect all requests to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

# Disable caching for index.html
<FilesMatch "index.html">
    FileETag None
    Header unset ETag
    Header unset Pragma
    Header unset Cache-Control
    Header unset Last-Modified
    Header set Pragma "no-cache"
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, proxy-revalidate"
    Header set Expires "Mon, 1 Jan 1900 00:00:00 GMT"
</FilesMatch>

What I've tried

What I need

After all this information,

Any advice or suggestions would be greatly appreciated. Thank you!

Upvotes: 1

Views: 61

Answers (0)

Related Questions