.htaccess redirects Configure 301 redirects and Apache rules via .htaccess on HolyCloud shared hosting. ~8 min read Beginner #htaccess #apache #redirect #hosting .htaccess redirects On HolyCloud shared web hosting (Apache), the .htaccess file at the site root (public_html) defines redirects, forces HTTPS, and rewrites URLs without access to global server configuration. Prerequisites Shared hosting with mod_rewrite enabled (default on HolyCloud offers) File Manager or FTP access to the site directory Backup of existing .htaccess before editing Access the .htaccess file cPanel → File Manager. public_html (or addon domain folder). Settings → check Show Hidden Files (dotfiles). Edit .htaccess or create it if missing. A syntax error can cause a 500 error on the entire site — keep a backup copy. Enable the rewrite engine At the top of the file (often already present with WordPress): RewriteEngine On RewriteBase / 301 redirect: non-www to www RewriteEngine On RewriteCond %{HTTP_HOST} ^votredomaine\.fr$ [NC] RewriteRule ^(.*)$ https://www.votredomaine.fr/$1 [L,R=301] 301 redirect: www to apex (non-www) RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.votredomaine\.fr$ [NC] RewriteRule ^(.*)$ https://votredomaine.fr/$1 [L,R=301] Force HTTPS RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] If the panel already enables Force HTTPS, do not duplicate this rule (loop risk). Redirect an old page to a new one Redirect 301 /ancienne-page.html https://www.votredomaine.fr/nouvelle-page/ Multiple pages: Redirect 301 /produits https://www.votredomaine.fr/boutique/ Redirect 301 /contact.php https://www.votredomaine.fr/contact/ Redirect an entire subfolder RewriteEngine On RewriteRule ^blog/(.*)$ https://www.votredomaine.fr/actualites/$1 [L,R=301] Redirect by pattern (RedirectMatch) All .html URLs to extensionless (example): RedirectMatch 301 ^/(.*)\.html$ https://www.votredomaine.fr/$1 Temporary 302 redirect (maintenance) RewriteEngine On RewriteCond %{REMOTE_ADDR} !^198\.51\.100\.42$ RewriteRule ^(.*)$ https://www.votredomaine.fr/maintenance.html [L,R=302] Replace the IP with yours to access the real site during maintenance. Block access to a directory RedirectMatch 403 ^/private/ Or basic authentication via Directory Privacy in the panel (preferred for admin areas). Test redirects From your machine: curl -I https://www.votredomaine.fr/ancienne-page.html Look for: HTTP/1.1 301 Moved Permanently Location: https://www.votredomaine.fr/nouvelle-page/ WordPress and .htaccess WordPress regenerates # BEGIN WordPress blocks. Place your rules above or below as needed; global redirects usually go before the WordPress block. After permalink changes: Settings → Permalinks → Save to regenerate internal rules. Troubleshooting | Symptom | Cause | Action | |----------|-------|--------| | 500 Internal Server Error | Apache syntax | Restore backup; comment lines | | Infinite loop | Double HTTPS/www | Single rule + panel Force HTTPS | | 301 not applied | CDN/browser cache | Purge Cloudflare cache; curl -I | | 404 after redirect | Target missing | Verify target URL | SEO best practices Use 301 for permanent URL changes. Avoid redirect chains (A→B→C); redirect directly to the final target. Update internal links in the CMS, not only .htaccess. Need help? Attach current .htaccess content (no passwords) and expected source/target URLs to your support ticket. Continue reading Next article Back up a site (cPanel) Read