Apache rewrite rules

De BlaxWiki
Révision datée du 24 mars 2009 à 10:53 par Admin (discussion | contributions) (Page créée avec « Doc Apache : http://httpd.apache.org/docs/1.3/misc/rewriteguide.html Générateur de .htaccess (rewrite rule, auth, page 404... ) : http://cooletips.de/htaccess/ * Redirec... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Aller à la navigationAller à la recherche

Doc Apache : http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

Générateur de .htaccess (rewrite rule, auth, page 404... ) : http://cooletips.de/htaccess/


  • Redirection d'une page (ancien domaine vers le nouveaud domaine):
RewriteEngine on
RewriteRule ^(.*)$ http://www.your-new-domain.com/$1 [R=301,L]

If a user visits http://www.olddomain.com/articles.php he will be redirected to the same page on your-new-domain.com. The R=301 part make it a permanent redirect by sending a “301 Moved Permanently” status code to the user’s browser. If the user happens to visits the same page on your old domain, the browser will automatically redirect to the new domain.


  • Redirect to www

So you only want users to visit www.mydomain.com and not domain.com.

RewriteEngine on
RewriteCond %{HTTP_HOST} mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]