You installed the SSL certificate and https:// works, yet http:// still loads and browsers still warn visitors. The certificate alone does not redirect anything. On Apache, a few lines in .htaccess send every plain request to the secure address with a permanent redirect.
.htaccess Generator FREE online toolRuns in your browser. No sign-up, nothing to install. Open the tool →The rule you need
The standard approach uses mod_rewrite. It checks whether the connection is not HTTPS and, if so, issues a 301 redirect to the same host and path on https. In essence: turn the rewrite engine on, add a condition that HTTPS is off, and rewrite everything to https://%{HTTP_HOST}%{REQUEST_URI} with the flags R=301 and L. A generator writes this with the right syntax so you do not have to remember the exact condition format.
Step by step
- Confirm https:// opens correctly without certificate warnings before you redirect anything.
- Back up your current .htaccess file, which sits in the site root next to index.php or index.html.
- Generate the HTTPS redirect with the .htaccess Generator and copy the rules.
- Paste them near the top of the file, above other rewrite rules such as WordPress or framework blocks.
- Upload the file and test http://yourdomain.com in a private window.
Why a 301 and not a 302
A 301 tells browsers and search engines the move is permanent, so link value transfers to the https version and browsers remember it. A 302 is temporary and keeps the old address in play. Use 301 once you are sure everything works, but test with a temporary redirect first if you are nervous, because browsers cache 301 responses aggressively.
Fixing common problems
- Redirect loop: your site sits behind a proxy or CDN that terminates SSL, so Apache always sees HTTP. Check the X-Forwarded-Proto header in the condition instead.
- Rules ignored: AllowOverride is set to None in the server config, so .htaccess is not read.
- 500 error: a typo, or mod_rewrite is not enabled on the server.
- Mixed content warnings: images or scripts still load over http inside your pages.
- www and non-www variations: decide on one and redirect the others as well.
After the redirect works
Update the site's own configuration too. In WordPress, change both URLs in Settings to https. Update canonical tags, sitemap entries and your analytics property, and add the https version to Search Console. Internal links should use https or relative paths so visitors do not take a redirect on every click.
Consider adding an HSTS header once everything runs smoothly. It tells browsers to use https automatically for a set period. Start with a short max-age, such as a day, because a mistake with a long value is hard to reverse.
Back out safely
Keep a copy of the previous file so you can restore it in seconds if something goes wrong. If you lock yourself out of the site with a 500 error, use your host's file manager or FTP to rename the .htaccess file, and the site returns to normal while you investigate. Make one change at a time so you know which rule caused a problem.
Hosting without .htaccess
This method applies to Apache and compatible servers such as LiteSpeed. Nginx has no .htaccess; the equivalent is a server block returning a 301 to the https URL. Many hosting panels also have a Force HTTPS toggle that does the same thing, so check before editing files.
Comments (0)
No comments yet. Be the first to share a thought.