Apache rewrite rules

De BlaxWiki
Révision datée du 16 juillet 2018 à 10:36 par 127.0.0.1 (discussion)
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 de http vers https (en gardant l url apres le fqdn)

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]


  • 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]
  • Redirection suivant l ip
## Si l ip n est pas 10.132.2.1[0-9], on redirige le vhost en 2eme RewriteCond sur la page de maintenance
   RewriteEngine On
        RewriteCond %{REMOTE_HOST} !^10.132.2.1[0-9]$
#       RewriteRule !maintenance.html$ maintenance.html [R=307,L]

        RewriteCond %{HTTP_HOST} ^(preprodw.appelmedical.com)
        RewriteRule "(.*)"  /var/www/atome_wordpress/multisite_grf/maintenance-appelmedical.html  [L]