URL redirigeant sans www www
-
20-09-2019 - |
Question
J'ai besoin de votre aide. Je veux tester si l'URL est entré sans www
comme example.com
il doit être transmis au www.example.com
.
La solution
Essayez cette règle mod_rewrite:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Autres conseils
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^.*$ http://www.example.com/$0 [NC,L,R=301]
Si vous utilisez nginx
, puis ajoutez cette ligne à nginx config
:
server {
listen 80;
server_name yourdomain.com;
rewrite ^/(.*) http://www.yourdomain.com/$1 permanent;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow