0

I've got a website which is available on medify.eu and on medify.eu/nl for the Dutch language version. Currently, google is linking to medify.eu/nl/ though (with a slash at the end), which gives an error, so I want to redirect medify.eu/nl/ to medify.eu/nl.

My .htaccess looked like this:

RewriteEngine On

    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    # Don't put www. here. If it is already there it will be included, if not
    # the subsequent rule will catch it.
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # Now, rewrite any request to the wrong domain to use www.

    AddType audio/aac .aac
    AddType audio/mp4 .mp4 .m4a
    AddType audio/mpeg .mp1 .mp2 .mp3 .mpg .mpeg
    AddType audio/ogg .oga .ogg
    AddType audio/wav .wav
    AddType audio/webm .webm
    AddType video/mp4 .mp4 .m4v
    AddType video/ogg .ogv
    AddType video/webm .webm

Following this answer I added two lines so that the whole file now looks like this:

RewriteEngine On
# This will enable the Rewrite capabilities

    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    # Don't put www. here. If it is already there it will be included, if not
    # the subsequent rule will catch it.
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # Now, rewrite any request to the wrong domain to use www.

    ###### I ADDED THESE TWO LINESBELOW ######
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    AddType audio/aac .aac
    AddType audio/mp4 .mp4 .m4a
    AddType audio/mpeg .mp1 .mp2 .mp3 .mpg .mpeg
    AddType audio/ogg .oga .ogg
    AddType audio/wav .wav
    AddType audio/webm .webm
    AddType video/mp4 .mp4 .m4v
    AddType video/ogg .ogv
    AddType video/webm .webm

But it still doesn't redirect medify.eu/nl/ to medify.eu/nl. Any ideas what I'm doing wrong?

Community
  • 1
  • 1
kramer65
  • 50,427
  • 120
  • 308
  • 488

1 Answers1

1

To remove a trailing slash using .htaccess you can use:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]

Make sure you clear your cache before testing this. After testing with your website, the output result:

Removed Trailing Slash

Joe
  • 4,877
  • 5
  • 30
  • 51
  • I've added your lines, but it still doesn't work (as you can see on https://medify.eu/nl/ ). Any other ideas? – kramer65 Jan 24 '17 at 10:12
  • Works fine on mine.... have you cleared your cache? The trailing slash has been removed and the website runs without issue. – Joe Jan 24 '17 at 10:40