glaucon's avatar

419 Page Expired error in subdomain

I am encountering a 410 Page Expired issue on my subdomain while working with a project running in production on primarydomain.com. My setup includes a subdomain test.primarydomain.com for testing, and everything works fine on the primary domain and locally (thankfully). However, on the subdomain, I am facing this "Page Expired" issue, especially with forms. On the test server, which is hosted at test.primarydomain.com I have configured the .env file with the following:

SESSION_DRIVER=database
SESSION_DOMAIN=.primarydomain.com   or SESSION_DOMAIN=test.primarydomain.com  or SESSION_DOMAIN=null
SESSION_LIFETIME=120

In the production domain i.e. primarydomain.com the .env is configured as:

SESSION_DRIVER=database
SESSION_DOMAIN=primarydomain.com 
SESSION_LIFETIME=120

Despite these settings, I cannot seem to resolve the issue. The odd part is that if I clear both the browser cache and the project cache (using the artisan command), it randomly allows me to log in once. However, once I log out, the issue reappears, and I get stuck with the "Page Expired" error every time I try to log in again. To clarify, I have already included the @csrf directive in all forms, and as mentioned, everything works fine on the primary domain and in the local setup, but the problem persists specifically on the subdomain. Any help on resolving this would be greatly appreciated!

1 like
6 replies
IotaChef's avatar

@tisuchi Great post and thank you for sharing. I was considering that option and found this post so changed my opinion.

glaucon's avatar
glaucon
OP
Best Answer
Level 1

After 2 days I was able to resolve it. Since my project was hosted on primarydomain.com in production and for test it was test.primarydomain.com. I wanted both of these apps to run separately which means no session sharing of any kind between the domains. Hence I put: SESSION_DOMAIN =primarydomain.com for production server and for test, I put SESSION_DOMAIN =test.primarydomain.com Making clear separation between the two. But that did not work for me because in .env my app names were the same for both production .env and test .env

We know that Laravel creates cookies such as laravel_session or app_name_session. Since the app names on both sides were the same, this was causing an issue. So I changed the test .env with APP_NAME="MyApp Test." Voila, everything worked.

2 likes
pathosverdes3's avatar

This saved my life, it's such a small detail and I forgot about it. I had a similar setup with primarydomain.com and dev.primarydomain.com Thank you!

Please or to participate in this conversation.