Masterclass 🚀
Why stop at just HTML? If you want your website to look like a modern platform—like Facebook, Instagram, or Medium—you need to strip away all unnecessary extensions. Your URLs should be clean, short, and easy to read. 💎
/about.html ➡️ /about
I recently showed you how to handle a single file, but many of you asked how to scale this across your entire site. Whether it's .html, .php, or even .asp, that ugly extension mess has to go! 🤮
Solution 1 - The "Clean Folder" Structure 📁
If your site is small, the simplest way is to use folders. Here is what the change looks like visually:
|-- 📄 index.html
|-- 📄 blog.html
To change /blog.html into just /blog, you create a folder and move the file:
|-- 📄 index.html
|-- 📁 blog
|-- 📄 index.html
Look at that URL now, folks! No extension in sight. Can we just bask in the glory of what we have accomplished for a second here please? 😎
Solution 2 - The Global .htaccess Redirect 🌪️
If you have hundreds of pages, restructuring folders isn't feasible. Instead, use this "magic" .htaccess trick that handles everything simultaneously. This is the gold standard for clean code! 🏆
Options -MultiViews
RewriteEngine On
# Redirect /file.html to /file
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
# Internally map /file back to /file.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
This snippet strips out the extension from the URL path while keeping your files exactly where they are. It also redirects anyone visiting the old .html links, so no 404 errors! ✅
Why Does This Even Matter? 🤔
- SEO: Search engines prefer clean, descriptive URL structures. 📈
- Security: It hides the technology you're using. 🛡️
- UX: Links are easier to share and remember. 🧠
That's it, we're done! With either of these solutions, you can rid yourself of all that ugliness and upgrade to a professional look. 🥳
🐘 You can start with remuve
.htmlin.htaccess.
If you enjoyed this article, you may also like Dervic Blog.
Comments (0)