background preloader

Htaccess

Facebook Twitter

[fr] Création facile de fichiers .htaccess "Éditeur .htaccess" [fr] Création facile de fichiers .htaccess "Éditeur .htaccess" Introduction To URL Rewriting - Smashing Coding. Advertisement Many Web companies spend hours and hours agonizing over the best domain names for their clients.

Introduction To URL Rewriting - Smashing Coding

They try to find a domain name that is relevant and appropriate, sounds professional yet is distinctive, is easy to spell and remember and read over the phone, looks good on business cards and is available as a dot-com. Or else they spend thousands of dollars to purchase the one they really want, which just happened to be registered by a forward-thinking and hard-to-find squatter in 1998.

They go through all that trouble with the domain name but neglect the rest of the URL, the element after the domain name. It, too, should be relevant, appropriate, professional, memorable, easy to spell and readable. Fortunately, there is a technique called URL rewriting that can turn unsightly URLs into nice ones — with a lot less agony and expense than picking a good domain name.

This article covers the following: What is URL rewriting? What Is URL Rewriting? URL rewriting changes all that. .htaccess snippets to optimize your website. All of the snippets below have to be pasted into your .htaccess file, which is located on the root of your Apache server.

.htaccess snippets to optimize your website

Waring: Always make sure you have a working backup before editing your .htaccess file! Force trailing slash Many clients of mine asked me for always having a trailing slash at the end of their urls. Looks like it’s great for SEO. The following snippet will alwyas add a trailing slash to your site urls. <IfModule mod_rewrite.c> RewriteCond %{REQUEST_URI} /+[^\.]+$ RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L] </IfModule> Source: Prevent hotlinking Hotlinking (the act of using images from another site than yours) is unfortunely a common practice which can waste lots of your precious bandwidth.

Source: Redirect mobile devices If your site is not using responsive web design yet, it could be very useful to be able to redirect mobile device to a mobile-specific version of your website. RewriteEngine On RewriteCond %{REQUEST_URI} ! Source: Force download of a specific filetype. Astuces .htaccess – Sécurité et optimisation. Les fichiers .htaccess sont des fichiers de configuration d’apache pouvant être placés dans n’importe quel répertoire de votre site web.

Astuces .htaccess – Sécurité et optimisation

Voici quelques astuces à connaître pour vos sites web. Voici donc une liste de bouts de code un peu plus atypiques pour vos .htaccess qu’une simple personnalisation d’erreur 404… Traduisez directement vos pages web avec Google Translate Si vous souhaitez traduire à la volée vos pages pour vos visiteurs étrangers. Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)/en$ [R,NC] RewriteRule ^(.*)/de$ [R,NC] Vous n’aurez juste à appeler votre page: pour qu’il soit traduit en anglais via Google. Se passer de la dialogue demandant d’ouvrir ou enregistrer le contenu téléchargeable de son site Quand vous téléchargez un fichier PDF ou AVI … dans la majorité des cas, il vous est demandé si vous souhaitez ouvrir ou télécharger le fichier.

AddType application/octet-stream .pdf AddType application/octet-stream .zip AddType application/octet-stream .mov.