Intermediate 17 min

.htaccess file: redirects and rewrites

Redirects 301, URL rewriting and sensitive folder protection with .htaccess on Apache LiteSpeed hosting.

#.htaccess#Redirection 301#Apache#URL

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.

In summary Save .htaccess before modification; a syntax error causes an error 500. Test one redirect at a time.

What you need

  • Active website on web hosting Anthony IT Solutions
  • Access SFTP or file manager of panel
  • Module mod_rewrite enabled (default on LiteSpeed)
  • Backup file .htaccess existing

Locate and save .htaccess

  1. Location

    Root web : public_html or wwwat the same level as index.php.

  2. Hidden file

    Enable the display of hidden files in FileZilla or panel.

  3. Security copy

    Resumption .htaccess.bak before any change.

  4. Syntax

    One directive per line; comments with #.

Redirected 301 permanent

Redirect 301 transfers SEO SEO to the new URL.

  1. Enable RewriteEngine

    RewriteEngine On in the head of a rewrite block.

  2. Simple Rule

    RewriteRule ^ancienne-page/?$ /nouvelle-page/ [R=301,L]

  3. Whole domain redirection

    RewriteCond %{HTTP_HOST} ^ancien.fr$ [NC] then RewriteRule to new domain.

  4. Test

    curl -I or private browser to check code 301.

Force www or without www

  1. Without www to www

    RewriteCond %{HTTP_HOST} !^www. [NC] + RewriteRule to https://www.%{HTTP_HOST}%{REQUEST_URI}

  2. www to without www

    Reverse the condition to delete www.

  3. Combine with HTTPS

    See HTTP/HTTPS redirection to avoid loops.

  4. Canonical SEO

    Choose a variant and keep it everywhere (Google Search Console).

Rewrite WordPress and CMS

"Petite URLs" are based on mod_rewrite.

  1. WordPress Block

    Do not remove the block between # BEGIN WordPress and # END WordPress.

  2. Regenerating

    Settings → Permalians → Register to rewrite .htaccess.

  3. PrestaShop

    Shop settings → SEO & URLs → regeneration .htaccess.

  4. 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
  1. wp-admin by IP

    <Files wp-login.php> Require ip VOTRE.IP </Files> (Apache 2.4).

  2. Block xmlrpc.php

    Disable if unused, target brute-force attacks.

  3. Prohibit listing

    Options -Indexes prevents navigation in folders.

  4. Sensitive files

    Deny from all on .env, SQL backups.

Error 500 Incorrect syntax → correct error 500. Restore .htaccess.bak.

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.