Step 1: Locate the File (Caution: It is hidden!)
The .htaccess file is located in the root folder of your website, usually named public_html, www, or httpdocs.
Important Note: Because the filename starts with a dot, it is considered a hidden file by Linux systems.
- In cPanel File Manager: Go to Settings in the top right corner and check the box "Show Hidden Files (dotfiles)".
- In FileZilla: Go to the Server menu at the top and ensure "Force showing hidden files" is enabled.
Step 2: Choose Your Preferred Version
Open the file and look for the line RewriteEngine On. Insert your chosen code block immediately below that line.
ATTENTION: In the examples below, replace your-site.com with your actual domain name and its correct extension (.ro, .com, .org, .net, etc.).
Option A: Redirect to NON-WWW (e.g., https://beautiful-romania.com)
This is the modern choice, recommended for a cleaner and shorter URL structure.
Code: Select all
# --- START REDIRECT NON-WWW & HTTPS ---
RewriteCond %{HTTP_HOST} ^www\.your-site\.com [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://your-site.com/$1 [L,R=301]
# --- END REDIRECT NON-WWW ---This is the traditional version, preferred by some administrators for a classic visual structure.
Code: Select all
# --- START REDIRECT TO WWW & HTTPS ---
RewriteCond %{HTTP_HOST} ^your-site\.com [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.your-site.com/$1 [L,R=301]
# --- END REDIRECT TO WWW ---1. Personalize Name and Extension: Make sure you change your-site to your actual name and .com to your real extension (e.g., if your site is .org, use .org).
2. The Backslash ( \ ): In the RewriteCond lines, the dot before the extension must be written as \. (example: \.ro or \.org). This backslash tells the server to treat the dot as a literal text character.
3. 301 Redirect: The [R=301] flag is the most important part for SEO. It tells search engines that the move is permanent and transfers all the "link juice" from the old versions to the new one.
Why Is This Step Mandatory?
- Eliminate Duplicate Content: Google will no longer penalize you for seeing the same content on different URLs.
- Enforce Security (HTTPS): All visitors will be automatically forced to use the secure version, protecting their data.
- Consolidate Authority: All social media shares and backlink efforts will contribute to a single, unified domain.
Tested by beautiful-romania.com
If you need more help, reply here and I will assist you.
I let you a screenshot where to place the code in the .htaccessfile file corectly (in my case rewrite urls from www to https):

NOTE: In screenshot, you can see the code highlighted in blue. Don't worry about the lines starting with # below it, those are standard phpBB comments. Your focus is strictly on placing your redirect rules right after RewriteEngine On.