Redirection et authentification (.htaccess, mod_rewrite) - Pointer sur la racine et non "www" dans .htaccess
... / Pointer sur la racine et ...
BMPCreated with Sketch.BMPZIPCreated with Sketch.ZIPXLSCreated with Sketch.XLSTXTCreated with Sketch.TXTPPTCreated with Sketch.PPTPNGCreated with Sketch.PNGPDFCreated with Sketch.PDFJPGCreated with Sketch.JPGGIFCreated with Sketch.GIFDOCCreated with Sketch.DOC Error Created with Sketch.
Frage

Pointer sur la racine et non "www" dans .htaccess

Von
Guillon
Erstellungsdatum 2025-09-15 12:35:42 in Redirection et authentification (.htaccess, mod_rewrite)

Bonjour,

J'ai placé le code .htaccess proposé en exemple dans cette page (https://help.ovhcloud.com/csm/fr-web-hosting-htaccess-url-rewriting?id=kb_article_view&sysparm_article=KB0052877) pour rediriger les entrées "http" vers "https" et cela semble fonctionner.

Par contre, comment faire pour pointer sur la racine uniquement (et non "www.")?

Merci 


6 Antworten ( Latest reply on 2025-09-15 14:52:47 Von
fritz2cat 🇧🇪 🇪🇺
)

Bonjour

Bonjour,

Si vous avez suivi cet exemple:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.tld/$1 [R,L]

vous pouvez enlever le "www." ci-dessus.

___ ___

Si on considère l'autre exemple:

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

vous pouvez très bien l'utiliser dans l'autre sens

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

___ ___

Je ferais comme ceci::

RewriteEngine On
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^www.domain.tld$ [NC]
RewriteRule ^(.*)$ https://domain.tld/$1 [R,L]

Explications:

[OR] c'est une condition OR (OU)

[NC] c'est une comparaison "not case sensitive" de manière à faire aussi le remplacement si on a c"crit votre URL en majuscules.

Votre version ne contenait pas la condition: "RewriteCond %{HTTP_HOST} ^www.gtld.ovh$ [NC] "

Cette condition dit que si quelqu'un visite www.gtld.ovh il faut le renvoyer sur gtld.ovh