Answer the question
In order to leave comments, you need to log in
What to write in htaccess so that when a folder is requested, a slash is not added to the path?
These rules cause a circular redirect if a folder is requested because they remove the slash from the path and something unknown adds it
RewriteBase /
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]
Answer the question
In order to leave comments, you need to log in
httpd.apache.org/docs/2.2/mod/mod_dir.html#directo...
Add .htaccess to the top:DirectorySlash Off
Something unknown cannot be added. Are you by any chance using some framework based on the symfony router? Symfony, Silex, Lavarel, Lumen? I also suffered with him with the same problem, it is necessary to carefully register routing with them so that this does not happen. I won't be more specific, it depends on how you implement it.
############################################################################
#### убирает / в конце строки если это файл ( содержит точку в урл) ####
############################################################################
RewriteCond %{REQUEST_URI} \..+$
#содержит точку (файл)
RewriteCond %{REQUEST_FILENAME} !-d
#не директория
RewriteCond %{REQUEST_FILENAME} -f
#является файлом
RewriteCond %{REQUEST_URI} ^(.+)/$
#в конце урла есть слеш
RewriteRule ^(.+)/$ /$1 [R=301,L]
#исключить слеш
############################################################################
#### Добавляет / если его нет, и это не файл!!! ####
############################################################################
RewriteCond %{REQUEST_URI} !(.*)/$
#слеша в конце нет
RewriteCond %{REQUEST_FILENAME} !-f
#является файлом
RewriteCond %{REQUEST_URI} !\..+$
#в урле нет точки (файл)
RewriteRule ^(.*)$ $1/ [L,R=301,QSA]
#добавляем слеш в конце
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question