.htaccess file: redirects and rewrites
Redirects 301, URL rewriting and sensitive folder protection with .htaccess on Apache LiteSpeed hosting.
Ready to start your service? Check offers and order online.
View offers and order.htaccess file: redirects and rewrites URL
On one Apache/LiteSpeed web hosting Anthony IT Solutions, file .htaccess at the root of your site allows 301 redirects, rewrite clean URLs and protect sensitive folders without changing server configuration.
WordPress, PrestaShop and Joomla often generate a .htaccess automatically. This guide explains how to securely customize it on your shared web hosting.
What you need
- Active website on web hosting Anthony IT Solutions
- Access SFTP or file manager of panel
- Module
mod_rewriteenabled (default on LiteSpeed) - Backup file
.htaccessexisting
Locate and save .htaccess
-
Location
Root web :
public_htmlorwwwat the same level asindex.php. -
Hidden file
Enable the display of hidden files in FileZilla or panel.
-
Security copy
Resumption
.htaccess.bakbefore any change. -
Syntax
One directive per line; comments with
#.
Redirected 301 permanent
Redirect 301 transfers SEO SEO to the new URL.
-
Enable RewriteEngine
RewriteEngine Onin the head of a rewrite block. -
Simple Rule
RewriteRule ^ancienne-page/?$ /nouvelle-page/ [R=301,L] -
Whole domain redirection
RewriteCond %{HTTP_HOST} ^ancien.fr$ [NC]then RewriteRule to new domain. -
Test
curl -I or private browser to check code 301.
Force www or without www
-
Without www to www
RewriteCond %{HTTP_HOST} !^www. [NC]+ RewriteRule to https://www.%{HTTP_HOST}%{REQUEST_URI} -
www to without www
Reverse the condition to delete www.
-
Combine with HTTPS
See HTTP/HTTPS redirection to avoid loops.
-
Canonical SEO
Choose a variant and keep it everywhere (Google Search Console).
Rewrite WordPress and CMS
"Petite URLs" are based on mod_rewrite.
-
WordPress Block
Do not remove the block between
# BEGIN WordPressand# END WordPress. -
Regenerating
Settings → Permalians → Register to rewrite .htaccess.
-
PrestaShop
Shop settings → SEO & URLs → regeneration .htaccess.
-
Subfolder
RewriteBase /subfolder/ if non-root installation.
Protecting resources
- Do not duplicate the rules already managed by the cache panel
- See cache LiteSpeed
- Avoid hundreds of RewriteRule, prefer generic patterns
-
wp-admin by IP
<Files wp-login.php> Require ip VOTRE.IP </Files>(Apache 2.4). -
Block xmlrpc.php
Disable if unused, target brute-force attacks.
-
Prohibit listing
Options -Indexesprevents navigation in folders. -
Sensitive files
Deny from all on
.env, SQL backups.
Troubleshooting
- 500 Internal Server Error, Restore backup; check RewriteEngine and paths.
- Redirection circle, HTTPS + .htaccess.
- 404 on permalians, mod_rewrite or RewriteBase incorrect.
- 403 Forbidden, ip requirement too restrictive.
Frequently Asked Questions
LiteSpeed lit .htaccess ?
Yes for mod_rewrite and several Apache compatible directives.
Modify without SFTP?
Web hosting panel file editor.
Redirection 302 vs 301 ?
301 for permanent SEO; 302 for temporary.
WordPress removes my rules?
Place your custom rules above or outside the WordPress block.
Related guides
See also our web hosting offer and all the procedures on wiki web hosting.