Différences entre les versions de « Apache rewrite rules »

De BlaxWiki
Aller à la navigationAller à la recherche
Ligne 12 : Ligne 12 :
RewriteRule ^/(.*)$ /var/www/squirrelmail/$1 [L]
RewriteRule ^/(.*)$ /var/www/squirrelmail/$1 [L]
</pre>
</pre>


* Rediriger un domaine vers un autre (à mettre dans le vhost du domaine source)
* Rediriger un domaine vers un autre (à mettre dans le vhost du domaine source)
Ligne 35 : Ligne 36 :
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</pre>
</pre>


* Redirection d'une page (ancien domaine vers le nouveaud domaine):
* Redirection d'une page (ancien domaine vers le nouveaud domaine):
<pre>
<pre>
RewriteEngine on
RewriteEngine on
RewriteRule ^(.*)$ http://www.your-new-domain.com/$1 [R=301,L]
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.
</pre>
</pre>
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
* Redirect to www
So you only want users to visit www.mydomain.com and not domain.com.
<pre>
<pre>
RewriteEngine on
RewriteEngine on
RewriteCond %{HTTP_HOST} mydomain.com [NC]
RewriteCond %{HTTP_HOST} mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
#So you only want users to visit www.mydomain.com and not domain.com.
</pre>
</pre>


* Redirection suivant l ip
* Redirection suivant l ip

Version du 16 juillet 2018 à 12:16

Doc Apache : http://httpd.apache.org/docs/2.4/fr/rewrite/

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

  • Toutes url commencant par mail. sera redirigé vers squirellmail
ServerName 212.43.196.63
DirectoryIndex index.php index.html
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mail.
RewriteRule ^/(.*)$ /var/www/squirrelmail/$1 [L]


  • Rediriger un domaine vers un autre (à mettre dans le vhost du domaine source)
#Ici on redirige mobile.ville-gennevilliers.fr vers www.ville-gennevilliers.fr
Rewriteengine on
RewriteCond %{HTTP_HOST} ^mobile.ville-gennevilliers.fr$ [NC]
RewriteRule ^(.*)$ http://www.ville-gennevilliers.fr/$1 [R=301,L]


ServerName extranet.grdf.fr
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteRule $ https://www.grdf.fr/maintenance [R=302,L]


  • 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
RewriteEngine on
RewriteCond %{HTTP_HOST} mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
#So you only want users to visit www.mydomain.com and not domain.com.


  • 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]