Archive

Articles taggués ‘htaccess’

Basic .htaccess for New Projects

28/02/2024 Comments off
# allows php on html
 AddType application/x-httpd-php .html
# Using this code, instead of having to type in http://mysite.com/contact.php, you only need to enter http://mysite.com/contact to access that page.
# And the best part is, you can still access the page with .php on the end of it, so no old incoming links or bookmarks become orphaned as a result of this, and everyone is happy.
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME}\.htm -f
 RewriteRule ^(.*)$ $1.htm
# gzip compression.
# html, txt, css, js, json, xml, htc:
 AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
 AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
 AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
# ------------------------
# CACHING to speed up site
# MONTH
 <FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf)$">
 Header set Cache-Control "max-age=2592000"
# WEEK
 <FilesMatch "\.(js|css|pdf|txt)$">
 Header set Cache-Control "max-age=604800"
# DAY
 <FilesMatch "\.(html|htm)$">
 Header set Cache-Control "max-age=43200"
# webfonts and svg:
 <FilesMatch "\.(ttf|otf|eot|svg)$" >
 SetOutputFilter DEFLATE
# use utf-8 encoding for anything served text/plain or text/html
 AddDefaultCharset utf-8
# force utf-8 for a number of file formats
 AddCharset utf-8 .html .css .js .xml .json .rss
# Custom 400 errors
 ErrorDocument 400 /error.php
# Custom 401 errors
 ErrorDocument 401 /error.php
# Custom 403 errors
 ErrorDocument 403 /error.php
# Custom 404 errors
 ErrorDocument 404 /error.php
# Custom 500 errors
 ErrorDocument 500 /error.php
# Changes http://example.com to http://www.example.com
 RewriteEngine on
 RewriteCond %{HTTP_HOST} !^www.your-domain.com$
 RewriteRule ^(.*)$ http://www.your-domain.com/$1 [R=301]
# Specifies what file will be the directory index
 DirectoryIndex index.php index.html index.htm
# Unhide the code below to turn on a Site Down Page
 # RewriteEngine On
 # RewriteBase /
 # RewriteCond %{REQUEST_URI} !^/your-domain\.php$
 # RewriteRule ^(.*)$ http://your-domain.com/site-down.php [R=307,L]
# redirect any variations of a specific character string to a specific address
 # RewriteEngine On
 # RewriteRule ^appsupport http://www.your-domain.com/ [R]
# ---- # The following will redirect to the new page permanently ----#
 # Redirect 301 /index.php http://www.your-domain.com/site-down.php
Categories: Système Tags: ,

A Standard .htaccess File with ExpressionEngine

28/02/2024 Comments off
.htaccess files can be a powerful tool for a developer, that is, as long as they are set up properly. What follows is a pretty simple .htaccess template that I use on the majority of my projects.

Secure .htaccess File

<Files .htaccess>
 order allow,deny
 deny from all
</Files>

This first set of lines essentially prevents others from viewing your htaccess file (and learning all about your crazy redirects).
Lire la suite…

Categories: Système Tags: ,

WordPress: Se protéger des spams sur les commentaires via un fichier .htaccess

25/02/2024 Comments off
Si vous autorisez vos visiteurs à poster des commentaires sur les articles de votre blog, vous avez certainement fait face aux robots spammeurs. Pour aider Askimet à lutter et réduire les attaques des spammeurs, il existe une astuce qui consiste à bloquer l’accès au fichier wp-comments-post.php qui permet de traiter la soumission des commentaires. Le code qui suit est à placer dans un fichier .htaccess à la racine de votre site Internet.

## ******** Pour se protéger contre des commentaires de Spam **********
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !.*mon-site.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) http://www.mon-site.com [R=301,L]

Protéger ses images contre le Hotlinking

24/01/2024 Comments off
fonctionnement-hotlinkLe hotlinking est une pratique courante qui consiste, le plus souvent, à afficher une image en utilisant l’adresse URL en provenance d’un autre site où elle est publiée. En fait, au lieu de stocker l’image sur son serveur, le hotlinkeur crée un lien direct vers le serveur d’origine.Principe du Hotlinking en schéma.Cette méthode est totalement illégale puisqu’il s’agit d’un vol de bande passante. En effet, à chaque fois que l’image est visionnée par un internaute, une requête HTTP est envoyée vers le serveur qui l’héberge. Cela ralentit le serveur qui doit fournir les images hotlinkées en plus des images du site d’origine. De plus, cela peut engendrer un coût financier supplémentaire puisque certains hébergeurs prennent en compte le trafic mensuel de données afin d’éviter les abus et de préserver la bande passante.

Pour lutter contre le hotlinking, il suffit de copier le code suivant dans le fichier .htaccess présent à la racine de votre projet. Il permet de remplacer l’image volée par une autre destinée à dissuader le hotlinkeur (par ex: http://p7.storage.canalblog.com/78/13/603253/75105879.jpg).

RewriteEngine On
# Remplacer mywebsite\.com/ par l'adresse de votre site
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mywebsite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
# Remplacer /images/nohotlink.jpg par le chemin de l'image affichée chez les voleurs
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

mod_geoip2 Apache module

22/01/2024 Comments off

The mod_geoip2 module embeds GeoIP database lookups into the Apache web server. It is only capable of looking up the IP of a client that connects to the web server, as opposed to looking up arbitrary addresses.

This module works with Apache 2. Please use mod_geoip with Apache 1.

Installation

You may download the latest release of mod_geoip2 or get the latest development version from GitHub. See the included INSTALL file in the tarball for installation details.

Overview

The mod_geoip2 module uses the libGeoIP library to look up geolocation information for a client as part of the http request process. This module is free software, and is licensed under the Apache license.

To compile and install this module, you must first install libGeoIP 1.4.3 or newer.

The mod_geoip2 module takes effect either during request header parsing phase or the post read request phase, depending on whether it is configured for server-wide use or for a specific location/directory.

When enabled, the module looks at the incoming IP address and sets some variables which provide geolocation information for that IP. The variables it set depend on the specific GeoIP database being used (Country, City, ISP, etc.). These variables can be set in either the request notes table, the environment or both depending on the server configuration.

Lire la suite…