FAQ / FTP, files and website errors

Website redirects and the .htaccess file

‹ FTP, files and website errors

The .htaccess file is a text file in the website directory that changes how a website behaves on an Apache server without touching the server configuration. It is mainly used for redirects, directory protection and cache settings. Caching is covered in the article Speeding up page loading, and password-protecting directories in the article Password-protecting directories.

Before you start

  • The file name starts with a dot, so some programs do not show it. In your FTP client, turn on the display of hidden files.
  • Before editing, back up the original .htaccess. A mistake in a single line causes a 500 error on the whole website.
  • If the file already contains rules (for example from WordPress), add the new ones above them and do not remove the existing ones.

Redirecting from HTTP to HTTPS

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This requires a working certificate, see SSL and HTTPS.

Redirecting from www to the address without www

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

If you would rather send everything to the www variant, adjust the rule. The important thing is to choose one variant and stick to it, so that search engines do not treat the two as different websites.

Redirecting a single page

Redirect 301 /stara-stranka https://mujweb.cz/nova-stranka

What 301 and 302 mean

  • 301 is a permanent redirect. Search engines transfer the ranking to the new address. Use it when addresses change or when moving to HTTPS.
  • 302 is a temporary redirect. Use it, for example, for temporary maintenance.

When something goes wrong

  • 500 error: there is a typo in the file. Restore the .htaccess backup.
  • The browser reports “too many redirects”: the rules have fallen into a loop, most often because of a conflict with a plugin or an application setting. Check that you are not redirecting twice and that the website address in the application matches (http versus https).

You will find other causes of errors in the article Errors 403, 404 and 500.

Still not sure what to do?

Write to us and we will solve it together.

Contact support ›