A
A
Alexander Pashchenko2011-10-28 14:56:22
Apache HTTP Server
Alexander Pashchenko, 2011-10-28 14:56:22

Remove the slash / at the end of the URL

Good afternoon. Help deal with the problem.

Apache 2.2.21

There is a URL like this: domain.tld/script < - exactly like that, without a slash at the end
And there is a directory /var/www/domain.tld/script/

When you try to access this URL, it redirects to domain.tld/ script /
(note the slash at the end).

Googling a little, I found out that mod_dir is doing this disgrace . And that there is a DirectorySlash off
directive that disables this behavior. But here's something that doesn't work. I tried to put it in both VirtualHost and .htaccess - it still continues to redirect.


In an attempt to get rid of this effect, I tried to invent a similar rewrite: But it does not give any effect. Rather, it causes a looping rewrite. I suspect that I came across some kind of Apache bug, or specifically the mod_dir module. And yet ... what to do?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)/$ domain.tld/$1 [L]



Answer the question

In order to leave comments, you need to log in

7 answer(s)
N
Nastradamus, 2011-10-28
@Nastradamus

I remember a friend had this problem, he asked me to fix it.
I poked and poked, but nothing worked. Then I opened this site instead of FF in Chrome - and there everything works as it should. I did "forget the site" in Firefox - it worked. FF often caches some unnecessary garbage and stubbornly displays it, despite CTRL + F5.

A
Alexander Zelenin, 2011-10-28
@zelenin

won't that help?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ /$1/ [R=301,L]

E
Evengard, 2011-10-28
@Evengard

<Location /script>
DirectorySlash Off
SetHandler script-handler
Have you tried it with SetHandler?

M
maxgalkin, 2011-10-28
@maxgalkin

Tell me, why do you think this is a problem and needs to be fixed?

S
scroll_down, 2015-08-28
@scroll_down

Resurrect the topic!
point212 , did you manage to solve the problem?

M
Majak, 2017-05-07
@Majak

Suddenly someone will fit.
For my needs, it turned out as follows:
DirectorySlash Off
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.*)/$ $1 [L,R= 301]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1/index.php [L]
This is for directories that didn't want to listen in any way.
For simple urls, you can add one more line:
RewriteRule ^(.*)/$ $1 [L,R=301]

A
Andrey, 2018-07-23
@AndryG

Stumbled in the docks on the slashes. Maybe you need it?
en https://code.i-harness.com/en/docs/apache_http_ser...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question