Apache Mod rewrite, or rewrite URLs "on the fly"

 Charge moyenne sur 1mn : 0.43 Charge moyenne sur 5mn : 0.86 Charge moyenne sur 15mn : 0.91


One of the most powerful functions enabled by the .htaccess file is the on-the-fly rewriting of URLs.





Site user blocks : Account info / user rights / summary

Identify yourself

Authenticate with your ZW3B account and take advantage of member services.

Username :
Password :
  
  

Le module rewrite .htaccess .htpassword d'apache

Trucs et astuces à envoyer depuis notre fichier htaccess

Informations :

Dates
  • Publish : : 2010
  • Modification : Wednesday 01 february 2012

  • 208 views

Share :

Pour le rewrite, il faut ajouter l'option qui va bien à votre Virtual-Host

Script avec 2 lignes

001# On suit  les liens symboliques
002Options +FollowSymlinks

Soit directement dans le fichier de configuration soit ds le .htaccess

Activation du mod rewrite d'Apache

Script avec 2 lignes

001# Activation du mod rewrite d'Apache
002RewriteEngine  On

Redirection SSL

Script avec 4 lignes

001# REDIRECTION SSL
002RewriteCond %{SERVER_PORT} !^443$
003RewriteCond %{HTTP_HOST} ^(.*)www.lab3w.fr.*
004RewriteRule ^(.*) https://www.lab3w.fr [QSA,R=301,L]

Réécriture sur un seul sous-domaine pour tous les alias

Script avec 3 lignes

001# Réécriture sur un seul sous-domaine pour tous  les alias
002RewriteCond   %{HTTP_HOST} !www.zw3b.fr$ 
003RewriteRule    ^(.*) http://www.zw3b.fr/$1 [L,R]

Tout rediriger sur index.php

Script avec 3 lignes

001# Tout rediriger sur index.php
002RewriteCond  %{REQUEST_FILENAME} !-f
003RewriteRule  !.(gif|jpe?g|png|css|js|xml|swf|flv|tar.gz|mov|mpg|dtd|pdf)$  index.php [L]

Quelques trucs utile qu'on peut envoyer depuis le .htaccess

Redirection pour depuis certaines IPs

Script avec 5 lignes

001# Redirection pour certaines IPs
002RewriteCond %{HTTP:X-FORWARDED-FOR}	^192.168.0	[OR]
003RewriteCond %{HTTP_REMOTE_IP} ^(.*)192.168.0
004
005RewriteRule ^(.*) http://www.svn.zw3b.fr/ [R=307,L]
Restrictions/Accés d'adresses IPs sans le module rewrite (juste par .htaccess)

Script avec 5 lignes

001# Restriction / Acces via IPs
002order deny, allow
003deny from all
004allow from 81.56.54.30
005allow from 81.255.83.0/24

Redirection / Restriction de Bots

Script avec 175 lignes

001# Restriction de Bots
002RewriteCond %{HTTP_USER_AGENT} ^(.*)Anarchie [NC,OR]
003RewriteCond %{HTTP_USER_AGENT} ^(.*)ASPSeek [NC,OR]
004RewriteCond %{HTTP_USER_AGENT} ^(.*)attach [NC,OR]
005RewriteCond %{HTTP_USER_AGENT} ^(.*)autoemailspider [NC,OR]
006RewriteCond %{HTTP_USER_AGENT} ^(.*)BackWeb [NC,OR]
007RewriteCond %{HTTP_USER_AGENT} ^(.*)Bandit [NC,OR]
008RewriteCond %{HTTP_USER_AGENT} ^(.*)BatchFTP [NC,OR]
009RewriteCond %{HTTP_USER_AGENT} ^(.*)BlackWidow [NC,OR]
010RewriteCond %{HTTP_USER_AGENT} ^(.*)Bot mailto:craftbot@yahoo.com [NC,OR]
011RewriteCond %{HTTP_USER_AGENT} ^(.*)Buddy [NC,OR]
012RewriteCond %{HTTP_USER_AGENT} ^(.*)bumblebee [NC,OR]
013RewriteCond %{HTTP_USER_AGENT} ^(.*)CherryPicker [NC,OR]
014RewriteCond %{HTTP_USER_AGENT} ^(.*)ChinaClaw [NC,OR]
015RewriteCond %{HTTP_USER_AGENT} ^(.*)CICC [NC,OR]
016RewriteCond %{HTTP_USER_AGENT} ^(.*)Collector [NC,OR]
017RewriteCond %{HTTP_USER_AGENT} ^(.*)Copier [NC,OR]
018RewriteCond %{HTTP_USER_AGENT} ^(.*)Crescent [NC,OR]
019RewriteCond %{HTTP_USER_AGENT} ^(.*)Custo [NC,OR]
020RewriteCond %{HTTP_USER_AGENT} ^(.*)DA [NC,OR]
021RewriteCond %{HTTP_USER_AGENT} ^(.*)DIIbot [NC,OR]
022RewriteCond %{HTTP_USER_AGENT} ^(.*)DISCo [NC,OR]
023RewriteCond %{HTTP_USER_AGENT} ^(.*)DISCo Pump [NC,OR]
024RewriteCond %{HTTP_USER_AGENT} ^(.*)Download Demon [NC,OR]
025RewriteCond %{HTTP_USER_AGENT} ^(.*)Download Wonder [NC,OR]
026RewriteCond %{HTTP_USER_AGENT} ^(.*)Downloader [NC,OR]
027RewriteCond %{HTTP_USER_AGENT} ^(.*)Drip [NC,OR]
028RewriteCond %{HTTP_USER_AGENT} ^(.*)DSurf15a [NC,OR]
029RewriteCond %{HTTP_USER_AGENT} ^(.*)eCatch [NC,OR]
030RewriteCond %{HTTP_USER_AGENT} ^(.*)EasyDL/2.99 [NC,OR]
031RewriteCond %{HTTP_USER_AGENT} ^(.*)EirGrabber [NC,OR]
032RewriteCond %{HTTP_USER_AGENT} ^(.*)email [NC,OR]
033RewriteCond %{HTTP_USER_AGENT} ^(.*)EmailCollector [NC,OR]
034RewriteCond %{HTTP_USER_AGENT} ^(.*)EmailSiphon [NC,OR]
035RewriteCond %{HTTP_USER_AGENT} ^(.*)EmailWolf [NC,OR]
036RewriteCond %{HTTP_USER_AGENT} ^(.*)Express WebPictures [NC,OR]
037RewriteCond %{HTTP_USER_AGENT} ^(.*)ExtractorPro [NC,OR]
038RewriteCond %{HTTP_USER_AGENT} ^(.*)EyeNetIE [NC,OR]
039RewriteCond %{HTTP_USER_AGENT} ^(.*)FileHound [NC,OR]
040RewriteCond %{HTTP_USER_AGENT} ^(.*)FlashGet [NC,OR]
041RewriteCond %{HTTP_USER_AGENT} ^(.*)FrontPage [NC,OR]
042RewriteCond %{HTTP_USER_AGENT} ^(.*)GetRight [NC,OR]
043RewriteCond %{HTTP_USER_AGENT} ^(.*)GetSmart [NC,OR]
044RewriteCond %{HTTP_USER_AGENT} ^(.*)GetWeb! [NC,OR]
045RewriteCond %{HTTP_USER_AGENT} ^(.*)gigabaz [NC,OR]
046RewriteCond %{HTTP_USER_AGENT} ^(.*)Go!Zilla [NC,OR]
047RewriteCond %{HTTP_USER_AGENT} ^(.*)Go!Zilla [NC,OR]
048RewriteCond %{HTTP_USER_AGENT} ^(.*)Go-Ahead-Got-It [NC,OR]
049RewriteCond %{HTTP_USER_AGENT} ^(.*)gotit [NC,OR]
050RewriteCond %{HTTP_USER_AGENT} ^(.*)Grabber [NC,OR]
051RewriteCond %{HTTP_USER_AGENT} ^(.*)GrabNet [NC,OR]
052RewriteCond %{HTTP_USER_AGENT} ^(.*)Grafula [NC,OR]
053RewriteCond %{HTTP_USER_AGENT} ^(.*)grub-client [NC,OR]
054RewriteCond %{HTTP_USER_AGENT} ^(.*)HMView [NC,OR]
055RewriteCond %{HTTP_USER_AGENT} ^(.*)HTTrack [NC,OR]
056RewriteCond %{HTTP_USER_AGENT} ^(.*)httpdown [NC,OR]
057RewriteCond %{HTTP_USER_AGENT} ^(.*)ia_archiver [NC,OR]
058RewriteCond %{HTTP_USER_AGENT} ^(.*)Image Stripper [NC,OR]
059RewriteCond %{HTTP_USER_AGENT} ^(.*)Image Sucker [NC,OR]
060RewriteCond %{HTTP_USER_AGENT} ^(.*)Indy*Library [NC,OR]
061RewriteCond %{HTTP_USER_AGENT} ^(.*)Indy Library [NC,OR]
062RewriteCond %{HTTP_USER_AGENT} ^(.*)InterGET [NC,OR]
063RewriteCond %{HTTP_USER_AGENT} ^(.*)InternetLinkagent [NC,OR]
064RewriteCond %{HTTP_USER_AGENT} ^(.*)Internet Ninja [NC,OR]
065RewriteCond %{HTTP_USER_AGENT} ^(.*)InternetSeer.com [NC,OR]
066RewriteCond %{HTTP_USER_AGENT} ^(.*)Iria [NC,OR]
067RewriteCond %{HTTP_USER_AGENT} ^(.*)JBH*agent [NC,OR]
068RewriteCond %{HTTP_USER_AGENT} ^(.*)JetCar [NC,OR]
069RewriteCond %{HTTP_USER_AGENT} ^(.*)JOC Web Spider [NC,OR]
070RewriteCond %{HTTP_USER_AGENT} ^(.*)JustView [NC,OR]
071RewriteCond %{HTTP_USER_AGENT} ^(.*)larbin [NC,OR]
072RewriteCond %{HTTP_USER_AGENT} ^(.*)LeechFTP [NC,OR]
073RewriteCond %{HTTP_USER_AGENT} ^(.*)LexiBot [NC,OR]
074RewriteCond %{HTTP_USER_AGENT} ^(.*)lftp [NC,OR]
075RewriteCond %{HTTP_USER_AGENT} ^(.*)Link*Sleuth [NC,OR]
076RewriteCond %{HTTP_USER_AGENT} ^(.*)likse [NC,OR]
077RewriteCond %{HTTP_USER_AGENT} ^(.*)Link [NC,OR]
078RewriteCond %{HTTP_USER_AGENT} ^(.*)LinkWalker [NC,OR]
079RewriteCond %{HTTP_USER_AGENT} ^(.*)Mag-Net [NC,OR]
080RewriteCond %{HTTP_USER_AGENT} ^(.*)Magnet [NC,OR]
081RewriteCond %{HTTP_USER_AGENT} ^(.*)Mass Downloader [NC,OR]
082RewriteCond %{HTTP_USER_AGENT} ^(.*)Memo [NC,OR]
083RewriteCond %{HTTP_USER_AGENT} ^(.*)Microsoft.URL [NC,OR]
084RewriteCond %{HTTP_USER_AGENT} ^(.*)MIDown tool [NC,OR]
085RewriteCond %{HTTP_USER_AGENT} ^(.*)Mirror [NC,OR]
086RewriteCond %{HTTP_USER_AGENT} ^(.*)Mister PiX [NC,OR]
087RewriteCond %{HTTP_USER_AGENT} ^(.*)Mozilla.*Indy [NC,OR]
088RewriteCond %{HTTP_USER_AGENT} ^(.*)Mozilla.*NEWT [NC,OR]
089RewriteCond %{HTTP_USER_AGENT} ^(.*)Mozilla*MSIECrawler [NC,OR]
090RewriteCond %{HTTP_USER_AGENT} ^(.*)MS FrontPage* [NC,OR]
091RewriteCond %{HTTP_USER_AGENT} ^(.*)MSFrontPage [NC,OR]
092RewriteCond %{HTTP_USER_AGENT} ^(.*)MSIECrawler [NC,OR]
093RewriteCond %{HTTP_USER_AGENT} ^(.*)MSProxy [NC,OR]
094RewriteCond %{HTTP_USER_AGENT} ^(.*)Navroad [NC,OR]
095RewriteCond %{HTTP_USER_AGENT} ^(.*)NearSite [NC,OR]
096RewriteCond %{HTTP_USER_AGENT} ^(.*)NetAnts [NC,OR]
097RewriteCond %{HTTP_USER_AGENT} ^(.*)NetMechanic [NC,OR]
098RewriteCond %{HTTP_USER_AGENT} ^(.*)NetSpider [NC,OR]
099RewriteCond %{HTTP_USER_AGENT} ^(.*)Net Vampire [NC,OR]
100RewriteCond %{HTTP_USER_AGENT} ^(.*)NetZIP [NC,OR]
101RewriteCond %{HTTP_USER_AGENT} ^(.*)NICErsPRO [NC,OR]
102RewriteCond %{HTTP_USER_AGENT} ^(.*)Ninja [NC,OR]
103RewriteCond %{HTTP_USER_AGENT} ^(.*)Octopus [NC,OR]
104RewriteCond %{HTTP_USER_AGENT} ^(.*)Offline Explorer [NC,OR]
105RewriteCond %{HTTP_USER_AGENT} ^(.*)Offline Navigator [NC,OR]
106RewriteCond %{HTTP_USER_AGENT} ^(.*)Openfind [NC,OR]
107RewriteCond %{HTTP_USER_AGENT} ^(.*)PageGrabber [NC,OR]
108RewriteCond %{HTTP_USER_AGENT} ^(.*)Papa Foto [NC,OR]
109RewriteCond %{HTTP_USER_AGENT} ^(.*)pavuk [NC,OR]
110RewriteCond %{HTTP_USER_AGENT} ^(.*)pcBrowser [NC,OR]
111RewriteCond %{HTTP_USER_AGENT} ^(.*)Ping [NC,OR]
112RewriteCond %{HTTP_USER_AGENT} ^(.*)PingALink [NC,OR]
113RewriteCond %{HTTP_USER_AGENT} ^(.*)Pockey [NC,OR]
114RewriteCond %{HTTP_USER_AGENT} ^(.*)psbot [NC,OR]
115RewriteCond %{HTTP_USER_AGENT} ^(.*)Pump [NC,OR]
116RewriteCond %{HTTP_USER_AGENT} ^(.*)QRVA [NC,OR]
117RewriteCond %{HTTP_USER_AGENT} ^(.*)RealDownload [NC,OR]
118RewriteCond %{HTTP_USER_AGENT} ^(.*)Reaper [NC,OR]
119RewriteCond %{HTTP_USER_AGENT} ^(.*)Recorder [NC,OR]
120RewriteCond %{HTTP_USER_AGENT} ^(.*)ReGet [NC,OR]
121RewriteCond %{HTTP_USER_AGENT} ^(.*)Scooter [NC,OR]
122RewriteCond %{HTTP_USER_AGENT} ^(.*)Seeker [NC,OR]
123RewriteCond %{HTTP_USER_AGENT} ^(.*)Siphon [NC,OR]
124RewriteCond %{HTTP_USER_AGENT} ^(.*)sitecheck.internetseer.com [NC,OR]
125RewriteCond %{HTTP_USER_AGENT} ^(.*)SiteSnagger [NC,OR]
126RewriteCond %{HTTP_USER_AGENT} ^(.*)SlySearch [NC,OR]
127RewriteCond %{HTTP_USER_AGENT} ^(.*)SmartDownload [NC,OR]
128RewriteCond %{HTTP_USER_AGENT} ^(.*)Snake [NC,OR]
129RewriteCond %{HTTP_USER_AGENT} ^(.*)SpaceBison [NC,OR]
130RewriteCond %{HTTP_USER_AGENT} ^(.*)sproose [NC,OR]
131RewriteCond %{HTTP_USER_AGENT} ^(.*)Stripper [NC,OR]
132RewriteCond %{HTTP_USER_AGENT} ^(.*)Sucker [NC,OR]
133RewriteCond %{HTTP_USER_AGENT} ^(.*)SuperBot [NC,OR]
134RewriteCond %{HTTP_USER_AGENT} ^(.*)SuperHTTP [NC,OR]
135RewriteCond %{HTTP_USER_AGENT} ^(.*)Surfbot [NC,OR]
136RewriteCond %{HTTP_USER_AGENT} ^(.*)Szukacz [NC,OR]
137RewriteCond %{HTTP_USER_AGENT} ^(.*)tAkeOut [NC,OR]
138RewriteCond %{HTTP_USER_AGENT} ^(.*)Teleport Pro [NC,OR]
139RewriteCond %{HTTP_USER_AGENT} ^(.*)URLSpiderPro [NC,OR]
140RewriteCond %{HTTP_USER_AGENT} ^(.*)Vacuum [NC,OR]
141RewriteCond %{HTTP_USER_AGENT} ^(.*)VoidEYE [NC,OR]
142RewriteCond %{HTTP_USER_AGENT} ^(.*)Web Image Collector [NC,OR]
143RewriteCond %{HTTP_USER_AGENT} ^(.*)Web Sucker [NC,OR]
144RewriteCond %{HTTP_USER_AGENT} ^(.*)WebAuto [NC,OR]
145RewriteCond %{HTTP_USER_AGENT} ^(.*)[Ww]eb[Bb]andit [NC,OR]
146RewriteCond %{HTTP_USER_AGENT} ^(.*)webcollage [NC,OR]
147RewriteCond %{HTTP_USER_AGENT} ^(.*)WebCopier [NC,OR]
148RewriteCond %{HTTP_USER_AGENT} ^(.*)Web Downloader [NC,OR]
149RewriteCond %{HTTP_USER_AGENT} ^(.*)WebEMailExtrac.* [NC,OR]
150RewriteCond %{HTTP_USER_AGENT} ^(.*)WebFetch [NC,OR]
151RewriteCond %{HTTP_USER_AGENT} ^(.*)WebGo IS [NC,OR]
152RewriteCond %{HTTP_USER_AGENT} ^(.*)WebHook [NC,OR]
153RewriteCond %{HTTP_USER_AGENT} ^(.*)WebLeacher [NC,OR]
154RewriteCond %{HTTP_USER_AGENT} ^(.*)WebMiner [NC,OR]
155RewriteCond %{HTTP_USER_AGENT} ^(.*)WebMirror [NC,OR]
156RewriteCond %{HTTP_USER_AGENT} ^(.*)WebReaper [NC,OR]
157RewriteCond %{HTTP_USER_AGENT} ^(.*)WebSauger [NC,OR]
158RewriteCond %{HTTP_USER_AGENT} ^(.*)Website [NC,OR]
159RewriteCond %{HTTP_USER_AGENT} ^(.*)Website eXtractor [NC,OR]
160RewriteCond %{HTTP_USER_AGENT} ^(.*)Website Quester [NC,OR]
161RewriteCond %{HTTP_USER_AGENT} ^(.*)Webster [NC,OR]
162RewriteCond %{HTTP_USER_AGENT} ^(.*)WebStripper [NC,OR]
163RewriteCond %{HTTP_USER_AGENT} ^(.*)WebWhacker [NC,OR]
164RewriteCond %{HTTP_USER_AGENT} ^(.*)WebZIP [NC,OR]
165RewriteCond %{HTTP_USER_AGENT} ^(.*)Wget [NC,OR]
166RewriteCond %{HTTP_USER_AGENT} ^(.*)Whacker [NC,OR]
167RewriteCond %{HTTP_USER_AGENT} ^(.*)Widow [NC,OR]
168RewriteCond %{HTTP_USER_AGENT} ^(.*)WWWOFFLE [NC,OR]
169RewriteCond %{HTTP_USER_AGENT} ^(.*)x-Tractor [NC,OR]
170RewriteCond %{HTTP_USER_AGENT} ^(.*)Xaldon WebSpider [NC,OR]
171RewriteCond %{HTTP_USER_AGENT} ^(.*)Xenu [NC,OR]
172RewriteCond %{HTTP_USER_AGENT} ^(.*)Zeus.*Webster [NC,OR]
173RewriteCond %{HTTP_USER_AGENT} ^(.*)Zeus [NC]
174
175RewriteRule ^(.*) - [F,L]

Je vous conseille de vérifier vos logs quotidiennement et de bannir le(s) bot(s) qui passerai(en)t par chez vous ;)

Affichage des erreurs PHP

Script avec 6 lignes

001# DISPLAY ERROR
002php_value display_errors 1
003#php_value html_errors 1
004#php_value log_errors 1
005#php_value track_errors 1
006#php_value xmlrpc_errors 1

Execute les fichier php5 & php4

Script avec 4 lignes

001# Execute les fichier php5 & php4
002AddType application/x-httpd-php .php4
003AddHandler php5-script .php5
004AddType application/x-httpd-php .php

Augmente la taille des fichiers lors des requetes POST

Script avec 8 lignes

001# FORMULAIRE UPLOAD
002# Augmente la variable upload via formulaire (marche pas pour php5)
003php_value upload_max_filesize 150M
004php_value post_max_size 150M
005# Maximum execution time of 60seconde (default 30)
006php_value max_execution_time 60
007# Memory Limit
008php_value memory_limit 128M

Protection à ce repertoire et ses enfants par paire urilisateur/mot de passe

Script avec 6 lignes

001# Protection par mot de passe
002AuthUserFile     /chemin/du/fichier/des/mots/de/passe/.htpasswd
003AuthGroupFile /dev/null
004AuthName "Private Folder"
005AuthType Basic
006Require valid-user

Sources :





Translate this page with Google

Author of the page

O.Romain.Jaillet-ramey

O.Romain.Jaillet-ramey

  • Firstname : Olivier Romain Luc
  • Lastname : : Jaillet-ramey
  • Arrived on tuesday 19 october 1976 (1976/10/19 00:00)
    44 years activity !

Firefox Nighlty

Our friends from Framasoft are interested in Mozilla and asked them questions about Nightly: Firefox Night-club, free entry !






Valid XHTML 1.0 Strict CSS Valide !

ipv6 ready