Stop Hacking Your .htaccess: A Better Way to Switch Laravel Versions
Source: Dev.to

Overview
We’ve all been there. It’s 10:00 PM, you just finished a major update for your Laravel site, and it’s time to go live.
In the past, I used to do what many of us try first: the .htaccess trick. I would upload the new version to a subfolder and try to “point” the website to it using some clever Apache rules.
It felt smart at the time. But then came the bugs: broken CSS paths, session errors, and the scariest part—accidentally making the .env file public.
Today, I want to show you a much better, “pro” way to do this. It’s called a symbolic link (symlink). It sounds technical, but it’s actually as simple as creating a shortcut on your desktop.
The “Bakery” Analogy
Imagine you run a bakery. You have a display case (your website) where you show your cakes.
The .htaccess way: You try to move the entire display case every time you bake a new cake. It’s heavy, slow, and you might drop something.
The symlink way: You keep the display case where it is and just swap the tray inside. The customers always look at the same spot, but the cake is fresh.
Why the .htaccess Method Is Risky
Before we dive into the “how,” here’s why you should avoid switching versions via .htaccess:
- Security: You risk exposing sensitive files (like
.env) if the redirect isn’t perfect. - Path Issues: Laravel functions such as
public_path()can get confused when the project is buried in subfolders. - Downtime: A typo in the
.htaccessfile can bring the whole site down with a “500 Internal Server Error.”
The Better Way: The “Current” Folder Strategy
Instead of moving files around, create a structure like this on your server:
/my-project/
├── releases/
│ ├── v1_old/ (Your old code)
│ └── v2_new/ (Your new code)
└── current/ (The “Magic” Shortcut)
Your web server (Apache or Nginx) will always look at the current/public folder. To switch versions, simply point the current shortcut to a different folder.
Step‑By‑Step Guide
1. Prepare Your Folders
Upload your new version into a folder inside releases/. Let’s call it v2_new.
2. The Magic Command
Open your terminal (SSH). Instead of copying files, run this command:
ln -sfn /home/username/releases/v2_new/public /home/username/public_html
What does this do? It tells the server: “Hey, whenever someone visits public_html, actually show them the files inside v2_new/public.” It happens instantly—no loading bars, no waiting.
3. The “Oops” Button (Rollback)
If you discover a massive bug in v2_new, you can switch back to the old version in one second:
ln -sfn /home/username/releases/v1_old/public /home/username/public_html
That’s it—no downtime, no risky redirects, and your .env stays safely out of public view.