How do I create and use an .htaccess file with the LWS Panel?

Procédure

Introduction

Welcome to our guide to using .htaccess with the LWS Panel. This guide will help you understand and implement the features of .htaccess. We'll show you how to create an .htaccess file, configure a time zone, manage redirects, and much more. Follow the step-by-step instructions to get the most out of your LWS-hosted website.

What is an .htaccess file?

An .htaccess (Hypertext Access) file is a configuration file used by Apache-based web servers. It allows site developers and administrators to modify the server configuration parameters for the directory in which the .htaccess file is placed, as well as for all sub-directories.

The interest and usefulness of an .htaccess file lies in its ability to control various aspects of the web server without having to modify the main server configuration. This makes the .htaccess file particularly useful in a shared hosting environment, where access to the main server configuration may not be available.

The .htaccess file can be used for a number of tasks, including:

  • Redirects: You can redirect visitors from an old page to a new page, from an old version of a site to a new version, or redirect HTTP traffic to HTTPS for added security.
  • Access control: You can use the .htaccess file to restrict access to certain parts of your website based on various criteria, such as the visitor's IP address or password.
  • Customised errors: You can use the .htaccess file to display customised error pages (such as "Page not found" or "Error 500") rather than generic server error pages.
  • URL rewriting: You can use the .htaccess file to change the URL displayed in the browser's address bar. This can make URLs more SEO friendly and relevant.
  • PHP configuration: You can use the .htaccess file to change the PHP configuration settings for your site.

In short, an .htaccess file is a powerful tool for managing and controlling your website on an Apache server. It offers great flexibility and allows in-depth customisation of the way the server manages your site.

How do I create an .htaccess file?

Create a text file on your computer using a standard text editor (Notepad, for example). Save the file as .htaccess.


What directives are allowed?

  • AuthConfig : Authorisation directives (AuthDBMGroupFile, AuthDBMUserFile, AuthGroupFile, AuthName, AuthType, AuthUserFile, Require, etc.).

  • Indexes : Directives controlling directory indexing (AddDescription, AddIcon, AddIconByEncoding, AddIconByType, DefaultIcon, DirectoryIndex, FancyIndexing, HeaderName, IndexIgnore, IndexOptions, ReadmeName, etc.).

  • Limit: Directives controlling host access (Allow, Deny and Order).

  • FileInfo: Directives controlling document types (DefaultType, ErrorDocument, ForceType, LanguagePriority, SetHandler, SetInputFilter, SetOutputFilter, and mod_mime Add and Remove directives, etc. ), document meta data (Header, RequestHeader, SetEnvIf, SetEnvIfNoCase, BrowserMatch, CookieExpires, CookieDomain, CookieStyle, CookieTracking, CookieName), mod_rewrite directives (RewriteEngine, RewriteOptions, RewriteBase, RewriteCond, RewriteRule) and and Action for mod_actions.


The "Options" directive is disabled: If this parameter is present in your .htaccess file, it will produce an error. We therefore invite you to comment out all lines starting with this directive ( Add a "#" at the beginning of the line. )
However, the "+FollowSymLinks" option in the "Options" directive is active. This feature is used in many CMS such as Joomla. You can therefore comment out the line associated with this parameter in the .htaccess file without worrying.

Practical examples

Creating a custom error page

ErrorDocument 401 /error/401.php ErrorDocument 403 /error/403.php ErrorDocument 404 /error/404.php ErrorDocument 500 /error/500.php


How to configure the time zone on your server

SetEnv TZ Europe/Paris


Blocking IP addresses

allow from all deny from 1.1.1.1.1 deny from 1.1.1.1.1


Permanent redirects

Redirect 301 /mapage.html http://www.monsite.com/manouvellepage.html


Domain redirections

RewriteCond %{HTTP_HOST} ^www.mon-site.com [NC] RewriteRule ^(.*)$ http://www.mon-site.fr/$1 [QSA,R=301]


Server administrator email

ServerSignature EMail SetEnv SERVER_ADMIN monadresse@monsite.com


Protect your images

Options +FollowSymlinks RewriteEngine On RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www.)?monsite.com/ [nc] RewriteRule .*.(gif|jpg|png)$ http://www.monsite.com/images/images-de-substitution.jpg [nc]


Make an entire site unavailable for maintenance

RewriteEngine on RewriteRule maintenance.html - [L] RewriteCond %{REMOTE_ADDR} !1.1.1.1.1 RewriteRule .* /maintenance.html [L]


Prevent directory listing

Options All -Indexes


Default page

DirectoryIndex contact.html


Protect your directories and files

# Protect a file AuthType Basic AuthName "Restricted access" AuthUserFile /home/path/.htpasswd Require valid-user # Protect a directory AuthType Basic AuthName "Restricted access" AuthUserFile /home/path/.htpasswd AuthGroupFile /dev/null Require valid-user
  • for shared hosting, the term "/home/path" should be replaced by : /var/www/domaine.com/htdocs/
  • for cpanel hosting, the term "/home/path" should be replaced by : /home/IDCPANEL/public_html/


Hide or display php errors

php_flag display_errors off

Rate this article :

3.5/5 | 12 opinion

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

0mn reading

How to configure SMTP on a CMS

0mn reading

Your contact form doesn't work and no email is received?

1mn reading

How do I create an htaccess file to rewrite a URL?

0mn reading

How do I update Wordpress to the latest version?


Questions sur l'article
kipra.fr Il y a 801 days
Je ne comprends pas comment je dois créer ma redirection 301 de webmail.kipra.fr/login vers https://mail51.lwspanel.com/webmail/ j'ai déjà essayé mais ça ne fonctionne pas.
See the
1 answers
fabrice-LWS - Il y a 799 days
Bonjour, vous pouvez utiliser http://mail.domaine.com en remplaçant domaine.com par votre nom de domaine afin d'avoir une redirection vers le Webmail.
Utile ?

Ask the LWS team and its community a question