0

I am using the following entry in .htaccess to add the trailing slash with the condition of !-f, which should add the trailing slash when it is not a valid file:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R]

Now actually I thought this would be it, but I end up getting things like .png/ and .php/ (basically only these two filename extensions, which are bugging me). Is there a way to check if the ending is .php or .png and then check for a trailing slash - and if it exists - remove it?

Edit: Perhaps it is because of some other rules in .htaccess? I will post the rest here:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^xxx.net [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


AddDefaultCharset utf-8

order allow,deny
allow from all
deny from 123.249.24.233

RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301,NC]


RewriteCond %{QUERY_STRING} ^$
RewriteCond %{THE_REQUEST} /index\.php
RewriteRule ^index\.php https://www.%{HTTP_HOST}/ [R=301,L]
RewriteRule ^Index\.php$ /index.php [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?|php)\ HTTP/
RewriteRule ^index\.(html?|php)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Is there no "direct" way to filter slash from .php and .png endings?

Franky2207
  • 163
  • 2
  • 19
  • Unless you have other rules, this can only happen, if the client requests the URI with slash already, or the requested URI is not a file. – Olaf Dietsche Jun 09 '20 at 17:15
  • @OlafDietsche Neither is the case, so I guess there is something wrong somewhere else - I have edited the initial post with the rest of my ```.htaccess```. – Franky2207 Jun 10 '20 at 13:36

0 Answers0