Rewrite Rules : Redirections WWW (avec ou sans)
Par Thierry POINOT sur vendredi 2 janvier 2009, 11:47 - astuce - Lien permanent
Pour une redirection vers un nom de domaine sans www même lorsque l'adresse www.nomdedomaine.com est tapé :# Redirection permanente vers le nom de domaine sans les www
RewriteCond %{HTTP_HOST} ^www\.nomdedomaine\.com$ [NC]
RewriteRule ^(.*)$ http://nomdedomaine.com/$1 [L,R=301]
Pour une redirection vers un nom de domaine avec www même lorsque l'adresse nomdedomaine.com est tapé :# Redirection permanente vers le nom de domaine avec les www
RewriteCond %{HTTP_HOST} ^nomdedomaine\.com$ [NC]
RewriteRule ^(.*)$ http://www.nomdedomaine.com/$1 [L,R=301]
Un petit article mémo...
C'est en regardant le code source du .htaccess d'un site Drupal que j'ai trouvé ça : <IfModule mod_rewrite.c>
RewriteEngine on
# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment and adapt the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
# RewriteBase /subdirectory
#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
# RewriteBase /
</IfModule>
Une bonne mini documentation pour les redirections avec ou sans les www...
Je me rappelle avoir bien galérer pour essayer de trouver comment faire ça simplement...
Je pensais que je l'avais fais pour ce blog et mon portfolio, mais en fait non... donc maintenant c'est chose faite...
Et au passage bonne année 2009 à tous !