Les avertissements suivants se sont produits :
Warning [2] Undefined array key 0 - Line: 1640 - File: showthread.php PHP 8.2.18 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php 1640 errorHandler->error_callback
/showthread.php 915 buildtree




Note de ce sujet :
  • Moyenne : 0 (0 vote(s))
  • 1
  • 2
  • 3
  • 4
  • 5
Problème avec .htaccess avec CMSMS 2.1 et Apache 2.4
#4
Une fois les modifications effectuées (voir post précédent), j'ai tenté d'avoir des URL propres (prettyURL).


Voici les 5 étapes que j'ai effectuées :

1) - Suppression des .htaccess dans les sous dossiers /doc, /plugins et /uploads, comme expliqué par JCE.

2) - Modification du config.php (mod_rewrite) :

Code :
[== PHP ==]

<?php
$config['dbms'] = 'mysql';
$config['db_hostname'] = '**********';
$config['db_username'] = '**********';
$config['db_password'] = '**********';
$config['db_name'] = '***********';
$config['db_prefix'] = 'cms_';
$config['timezone'] = 'Europe/Paris';
$config['url_rewriting'] = 'mod_rewrite';
$config['page_extension'] = '';
$config['query_var'] = 'page';
?>

3) - Copie du htaccess.txt (depuis /doc) à la racine du site, puis modification du fichier avec ajout des lignes suivantes, comme il devrait être sur la prochaine version 2.1.3 suivant JCE :

Code :
RedirectMatch 403 ^.*/lib/.*\.php$
RedirectMatch 403 ^.*/tmp/.*\.php$
RedirectMatch 403 ^.*/modules/.*\.php$
RedirectMatch 403 ^.*/uploads/.*\.php$

****** lignes à ajouter à la suite *********

RedirectMatch 403 ^.*/doc/.*\.php$
RedirectMatch 403 ^.*/plugins/.*\.php$

4) - Modification (normes Apache 2.4) des lignes suivantes :

Code :
<Files ~ "\.htaccess">
  Order allow,deny
  Deny from all
</Files>
<Files ~ "\.ini$">
  Order allow,deny
  Deny from all
</Files>
<Files ~ "\.log$">
  Order allow,deny
  Deny from all
</Files>
<Files ~ "config\.php">
  Order allow,deny
  Deny from all
</Files>
<Files ~ "/lib/*php">
  Order allow,deny
  Deny from all
</Files>

par :

Code :
<Files ~ "\.htaccess">
  Require all granted
</Files>
<Files ~ "\.ini$">
  Require all granted
</Files>
<Files ~ "\.log$">
  Require all granted
</Files>
<Files ~ "config\.php">
  Require all granted
</Files>
<Files ~ "/lib/*php">
  Require all granted
</Files>

5) - Par FTP (Fillezilla) transformation du htaccess.txt en .htaccess.

Et là... c'est le drame !!

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.


En effectuant une recherche ligne par ligne dans mon fichier .htaccess, j'ai trouvé que le problème venait de la mise en cache des images, scripts, css... J'ai donc commenté les lignes suivantes :
  • - ExpiresActive On
  • - ExpiresDefault "access plus 1 months"
  • - toutes lignes avec : ExpiresByType

et tout fonctionne parfaitement :

Code :
#
# The following allows the browser to cache images, scripts, stylesheets and videos.  If the expires module is enabled on the server.
#
<IfModule mod_expires.c>
  #ExpiresActive On
  #ExpiresDefault "access plus 1 months"
# Set expires tags on various file types... so that the browser wont attempt to reload them.
#ExpiresByType image/jpg "access plus 1 years"
#ExpiresByType image/gif "access plus 1 years"
#ExpiresByType image/ico "access plus 1 years"
#ExpiresByType image/png "access plus 1 years"
#ExpiresByType video/x-flv "access plus 1 years"
#ExpiresByType application/pdf "access plus 1 years"
#ExpiresByType application/x-shockwave-flash "access plus 1 years"
#ExpiresByType application/javascript "access plus 1 months"
#ExpiresByType application/x-javascript "access plus 1 months"
#ExpiresByType text/javascript "access plus 1 months"
#ExpiresByType text/css "access plus 1 months"
  <IfModule mod_headers.c>
    # Setting cache control to public allows proxy servers to cache the items too.
    Header set Cache-Control "public"
  </IfModule>
</IfModule>


Voici le .htacces à utiliser donc si vous avez Apache 2.4 et que vous souhaitez utiliser les URL propres (prettyURL) :

Code :
# This file is specific to Apache configurations.
# It attempts to optimize traffic and configuration for your CMS Made Simple website.
# Many options are disabled by default as some providers do not allow you to override some of these settings in the .htaccess file.

# Attempt to override some PHP settings.
# These settings may be helpful on some hosts if your default configuration does not meet CMSMS's minimum requirements,
# and your host has given your account appropriate permissions.
#php_value upload_max_filesize "10M"
#php_value session_save_path "tmp/cache"
#php_value session.cookie_httponly true
#php_flag magic_quotes_gpc Off
#php_flag register_globals Off
#php_flag session.use_trans_sid Off

# Disallow directory indexes. This can be an important security enhancement
#Options -Indexes

# Don't allow the browser to know the type of signature.
ServerSignature Off

# Allow the Apache server to follow symbolic links.  This is usually not necessary.
#Options +FollowSymLinks

# To prevent E_STRICT problems with PHP 5.3+ you can uncomment the following lines
# Note: These settings should only be enabled for production sites!
#php_flag display_startup_errors 0
#php_flag display_errors 0
#php_flag html_errors 0
#php_value docref_root 0
#php_value docref_ext 0

# The following is to enable pretty URLS, only applicable if url_rewriting is set to 'mod_rewrite' in the config.php
<IfModule rewrite_module>
  RewriteEngine on
  RewriteBase /
  # Rewrites urls in the form of /parent/child/grandchild but only rewrites if the requested URL is not a file or directory.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>

# The following are higly reommended security settings for files in your CMSMS install that should not be browsed directly
<Files ~ "\.htaccess">
  Require all granted
</Files>
<Files ~ "\.ini$">
  Require all granted
</Files>
<Files ~ "\.log$">
  Require all granted
</Files>
<Files ~ "config\.php">
  Require all granted
</Files>
<Files ~ "/lib/*php">
  Require all granted
</Files>

RedirectMatch 403 ^.*/lib/.*\.php$
RedirectMatch 403 ^.*/tmp/.*\.php$
RedirectMatch 403 ^.*/modules/.*\.php$
RedirectMatch 403 ^.*/uploads/.*\.php$
RedirectMatch 403 ^.*/doc/.*\.php$
RedirectMatch 403 ^.*/plugins/.*\.php$

# The following are performance optimizations and security enhancements for content that is served by your CMSMS installation.
<IfModule mod_headers.c>
  # Disable Last-Modified for performance
  Header unset Last-Modified
  # Disable ETags
  Header unset ETag
  FileEtag None
  # For Security
  Header set X-Frame-Options "SAMEORIGIN"
</IfModule>

# The following setups compression for content, if compression is enabled on the server.
<IfModule deflate_module>
  AddOutputFilterByType DEFLATE text/html text/css text/plain text/html text/xml image/gif image/jpeg image/png image/ico text/javascript application/x-javascript application/javascript application/json application/pdf
</IfModule>

#
# The following allows the browser to cache images, scripts, stylesheets and videos.  If the expires module is enabled on the server.
#
<IfModule mod_expires.c>
  #ExpiresActive On
  #ExpiresDefault "access plus 1 months"
# Set expires tags on various file types... so that the browser wont attempt to reload them.
#ExpiresByType image/jpg "access plus 1 years"
#ExpiresByType image/gif "access plus 1 years"
#ExpiresByType image/ico "access plus 1 years"
#ExpiresByType image/png "access plus 1 years"
#ExpiresByType video/x-flv "access plus 1 years"
#ExpiresByType application/pdf "access plus 1 years"
#ExpiresByType application/x-shockwave-flash "access plus 1 years"
#ExpiresByType application/javascript "access plus 1 months"
#ExpiresByType application/x-javascript "access plus 1 months"
#ExpiresByType text/javascript "access plus 1 months"
#ExpiresByType text/css "access plus 1 months"
  <IfModule mod_headers.c>
    # Setting cache control to public allows proxy servers to cache the items too.
    Header set Cache-Control "public"
  </IfModule>
</IfModule>

Si quelqu'un à une solution concernant la gestion du cache via le .htaccess sur un serveur avec Apache 2.4, merci de m'en faire part.

Wink Bonne journée à tous.


Messages dans ce sujet

Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)