Forcer le slash à la fin d'une URL spécifique

Nouveau WRInaute
Bonjour,

Je n'arrive pas à forcer le "/" à la fin d'une URL.
Quelqu'un aurait une solution avec une règle de redirection 301 dans le htaccess ?
Je précise que c'est bien pour une URL spécifique et pas pour l'ensemble des URLs d'un site car j'ai trouvé la règle pour cela, mais ce n'est pas mon besoin.

Merci beaucoup pour votre aide.
Mathias
 
WRInaute occasionnel
Salut, si je ne me trompe pas, cela devrait être quelque chose dans ce style :

Code:
RewriteRule ^(.*)\.html$ $1/ [R=301,L]

Après je ne sais pas de quoi tu pars comme url, il faudrait que tu donnes un exemple pour être sûr :rolleyes:
 
Nouveau WRInaute
Salut et merci pour ton retour.
Si je ne me trompe pas également ce code permet de rajouter un "/" à la fin de toutes les URLs du site.
Dans mon cas, j'ai besoin de rajouter un "/" à la fin d'une seule URL.
Pour être plus précis, l'agence SEO de mon client me demande de faire une redirection 301 de :
https://www.nomdusite.com/blog vers https://www.nomdusite.com/blog/

Le site tourne sous Apache et avec une redirection 301 classique dans le htaccess, ça ne fonctionne pas.

Merci,
Mathias
 
Nouveau WRInaute
Bonjour,
Cette discussion m'intéresse beaucoup puisque j'ai également besoin de forcer via un 301 le "/" à la fin de 3 URL.
J'ai tenté de mettre cela en place en suivant les instructions ci-dessus :

RewriteRule ^dcg$ /dcg/ [R=301,L]
RewriteRule ^diplome-expertise-comptable$ /diplome-expertise-comptable/ [R=301,L]
RewriteRule ^dscg$ /dscg/ [R=301,L]

Ca ne fonctionne pas.
Quelle est mon erreur svp ?
Merci.
 
Dernière édition:
Nouveau WRInaute
Bonjour,
Pas de plantage ni de message d'erreur. Aucun effet, aucune redirection de /dcg vers /dcg/ (par exemple).
 
Nouveau WRInaute
AddHandler x-mapp-php5.5 .php

# START IONOS Performance Directory Index
# IONOS Directory Index v1
<IfModule mod_dir.c>
DirectoryIndex index.php
</IfModule>
# END IONOS Performance Directory Index

# START IONOS Performance Cache Expiration
# IONOS Cache Expiration v1
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css A2419200
ExpiresByType text/x-component A2419200
ExpiresByType application/x-javascript A2419200
ExpiresByType application/javascript A2419200
ExpiresByType text/javascript A2419200
ExpiresByType text/x-js A2419200
ExpiresByType text/html A3600
ExpiresByType text/richtext A3600
ExpiresByType image/svg+xml A3600
ExpiresByType text/plain A3600
ExpiresByType text/xsd A3600
ExpiresByType text/xsl A3600
ExpiresByType text/xml A3600
ExpiresByType video/asf A2419200
ExpiresByType video/avi A2419200
ExpiresByType image/bmp A2419200
ExpiresByType application/java A2419200
ExpiresByType video/divx A2419200
ExpiresByType application/msword A2419200
ExpiresByType application/vnd.ms-fontobject A2419200
ExpiresByType application/x-msdownload A2419200
ExpiresByType image/gif A2419200
ExpiresByType application/x-gzip A2419200
ExpiresByType image/x-icon A2419200
ExpiresByType image/jpeg A2419200
ExpiresByType application/json A2419200
ExpiresByType application/vnd.ms-access A2419200
ExpiresByType audio/midi A2419200
ExpiresByType video/quicktime A2419200
ExpiresByType audio/mpeg A2419200
ExpiresByType video/mp4 A2419200
ExpiresByType video/mpeg A2419200
ExpiresByType application/vnd.ms-project A2419200
ExpiresByType application/x-font-otf A2419200
ExpiresByType application/vnd.ms-opentype A2419200
ExpiresByType application/vnd.oasis.opendocument.database A2419200
ExpiresByType application/vnd.oasis.opendocument.chart A2419200
ExpiresByType application/vnd.oasis.opendocument.formula A2419200
ExpiresByType application/vnd.oasis.opendocument.graphics A2419200
ExpiresByType application/vnd.oasis.opendocument.presentation A2419200
ExpiresByType application/vnd.oasis.opendocument.spreadsheet A2419200
ExpiresByType application/vnd.oasis.opendocument.text A2419200
ExpiresByType audio/ogg A2419200
ExpiresByType application/pdf A2419200
ExpiresByType image/png A2419200
ExpiresByType application/vnd.ms-powerpoint A2419200
ExpiresByType audio/x-realaudio A2419200
ExpiresByType image/svg+xml A2419200
ExpiresByType application/x-shockwave-flash A2419200
ExpiresByType application/x-tar A2419200
ExpiresByType image/tiff A2419200
ExpiresByType application/x-font-ttf A2419200
ExpiresByType application/vnd.ms-opentype A2419200
ExpiresByType audio/wav A2419200
ExpiresByType audio/wma A2419200
ExpiresByType application/vnd.ms-write A2419200
ExpiresByType application/font-woff A2419200
ExpiresByType application/vnd.ms-excel A2419200
ExpiresByType application/zip A2419200
</IfModule>
# END IONOS Performance Cache Expiration

# START IONOS Performance Deflate
# IONOS Deflate v1
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/cache-manifest
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/vcard
AddOutputFilterByType DEFLATE text/vnd.rim.location.xloc
AddOutputFilterByType DEFLATE text/vtt
AddOutputFilterByType DEFLATE text/x-component
AddOutputFilterByType DEFLATE text/x-cross-domain-policy
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/activity+json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/ld+json
AddOutputFilterByType DEFLATE application/atom+xml
AddOutputFilterByType DEFLATE application/manifest+json
AddOutputFilterByType DEFLATE application/rdf+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/schema+json
AddOutputFilterByType DEFLATE application/vnd.geo+json
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-web-app-manifest+json
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE font/eot
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE image/bmp
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/vnd.microsoft.icon
AddOutputFilterByType DEFLATE image/x-icon
</IfModule>
# END IONOS Performance Deflate

# START IONOS Performance Caching
# IONOS Caching Snippet v2
<IfModule mod_setenvif.c>
SetEnvIf REQUEST_METHOD "^(?!GET).*$" INITIAL_REQUEST_METHOD=NOGET
</IfModule>

<IfModule mod_rewrite.c>
# ENGINE ON
RewriteEngine on

RedirectPermanent http://s911004401.onlinehome.fr/dcg http://s911004401.onlinehome.fr/dcg/
RedirectPermanent http://s911004401.onlinehome.fr/diplome-expertise-comptable http://s911004401.onlinehome.fr/diplome-expertise-comptable/
RedirectPermanent http://s911004401.onlinehome.fr/dscg http://s911004401.onlinehome.fr/dscg/

# set hostname directory
RewriteCond %{HTTPS} on
RewriteRule .* - [E=IONOS_PERFORMANCE_HOST:https-%{HTTP_HOST}]

RewriteCond %{HTTPS} off
RewriteRule .* - [E=IONOS_PERFORMANCE_HOST:%{HTTP_HOST}]

# set subdirectory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_FILENAME} !.(gif|jpg|png|jpeg|css|xml|txt|js|php|scss|webp|mp3|avi|wav|mp4|mov)$ [NC]
RewriteRule .* - [E=IONOS_PERFORMANCE_DIR:%{REQUEST_URI}/]

RewriteCond %{REQUEST_URI} /$
RewriteRule .* - [E=IONOS_PERFORMANCE_DIR:%{REQUEST_URI}]

RewriteCond %{REQUEST_URI} ^$
RewriteRule .* - [E=IONOS_PERFORMANCE_DIR:/]

# gzip
RewriteRule .* - [E=IONOS_PERFORMANCE_SUFFIX:]
<IfModule mod_mime.c>
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule .* - [E=IONOS_PERFORMANCE_SUFFIX:.gz]
AddType text/html .gz
AddEncoding gzip .gz
</IfModule>

# Main Rules
RewriteCond %{HTTP_ACCEPT} .*text/html.*
RewriteCond %{ENV:INITIAL_REQUEST_METHOD} ^$
RewriteCond %{ENV:REDIRECT_INITIAL_REQUEST_METHOD} ^$
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} !^/(wp-admin|wp-content/cache)/.*
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond /homepages/18/d911004402/htdocs/app911004401/wp-content/cache/ionos-performance/%{ENV:IONOS_PERFORMANCE_HOST}%{ENV:IONOS_PERFORMANCE_DIR}index.html%{ENV:IONOS_PERFORMANCE_SUFFIX} -f
RewriteRule ^(.*) /wp-content/cache/ionos-performance/%{ENV:IONOS_PERFORMANCE_HOST}%{ENV:IONOS_PERFORMANCE_DIR}index.html%{ENV:IONOS_PERFORMANCE_SUFFIX} [L]
</IfModule>
# END IONOS Performance Caching

# BEGIN WordPress
# Les directives (lignes) entre « BEGIN WordPress » et « END WordPress » sont générées
# dynamiquement, et doivent être modifiées uniquement via les filtres WordPress.
# Toute modification des directives situées entre ces marqueurs sera surchargée.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
 
WRInaute impliqué
Avec :
Apache config:
RewriteRule ^dcg$ /dcg/ [R=301,L]
RewriteRule ^diplome-expertise-comptable$ /diplome-expertise-comptable/ [R=301,L]
RewriteRule ^dscg$ /dscg/ [R=301,L]

comme tu l'avais indiqué, à la place de :
Code:
RedirectPermanent http://s911004401.onlinehome.fr/dcg http://s911004401.onlinehome.fr/dcg/
RedirectPermanent http://s911004401.onlinehome.fr/diplome-expertise-comptable http://s911004401.onlinehome.fr/diplome-expertise-comptable/
RedirectPermanent http://s911004401.onlinehome.fr/dscg http://s911004401.onlinehome.fr/dscg/

ça devrait marcher. Ou alors le problème ne vient pas du contenu du htaccess (cache peut-être ?)
 
Nouveau WRInaute
Donc en gros rien qui cloche ?
Et pourtant ça ne fonctionne pas même après suppression du cache :(
Merci beaucoup tout de même. C'est vraiment embétant mais bon...
 
Nouveau WRInaute
Du coup je suis revenu sur ton code :

RewriteRule ^dcg$ /dcg/ [R=301,L]
RewriteRule ^diplome-expertise-comptable$ /diplome-expertise-comptable/ [R=301,L]
RewriteRule ^dscg$ /dscg/ [R=301,L]

La première ligne fonctionne. En cliquant sur /dcg je suis bien redirigé vers /dcg/
Hélas, pour les 2 autres je suis bien redirigé vers /diplome-expertise-comptable/ et /dscg/ mais j'obtiens = la page n'existe pas.

Etrange puisque /diplome-expertise-comptable et /dscg (sans slash) existent bien !
J'en perd mon latin :(
 
Dernière édition:
WRInaute accro
Question bête : le code est mis avant tout le reste entre des balises IfModule mod_rewrite.c et un RewriteEngine On ?
 
Nouveau WRInaute
Bonjour,
Comme le montre le contenu de mon htaccess (voir plus haut) j'ai placé le code après :

<IfModule mod_rewrite.c>
# ENGINE ON
RewriteEngine on

Ais-je mal fait ?
Merci.
 
WRInaute impliqué
Etrange puisque /diplome-expertise-comptable et /dscg (sans slash) existent bien !
Certes, mais ce n'est pas exactement la même URL, même si, en principe elles devraient atteindre le même contenu (il me semble que chez UNIX, un chemin qui se termine par un slash indique qu'il s'agit du chemin d'un dossier, et sans slash, de celui d'un fichier).

Il me semble que ces lignes du htaccess ne s'appliquent qu'aux URL se finissant par un slash :
Apache config:
RewriteCond %{REQUEST_URI} /$
RewriteRule .* - [E=IONOS_PERFORMANCE_DIR:%{REQUEST_URI}]
Je peux pas trop te dire de quoi il s'agit exactement, ça m'a l'air d'un truc propore à IONOS probablement de la mise en cache vu les variables.
 
WRInaute impliqué
Tu peux toujours voir ce que ça donne en commentant les deux lignes que j'ai cité. Si j'en comprends le principe, tu devrais perdre l'optimisation fournie par IONOS.
 
Discussions similaires
Haut