RhythmScout's avatar

"Redirect Trailing Slashes" in .htaccess seems to break basic Auth

Just a tip.... I was working with a mobile API that I did not have control over. One of their POST submissions ended with a trailing slash. Couldn't figure out why I was getting 301 "moved" response and when looking at the server logs, the Basic Auth information was not included.

Found the following in /public/.htaccess:

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

This seemed to be the culprit.

Took some time to track that down.

Does anyone know if this rewrite rule is just for cosmetics, or am I breaking something by taking it out?

0 likes
2 replies
bashy's avatar
bashy
Best Answer
Level 65

It's best to use either trailing slash or not at all. This is just a default in Laravel. If you use one, you have to make sure your URIs are generated with/without one.

Personally I don't use Apache but I believe this should be above that rule to save the redirects on existing paths

RewriteCond %{REQUEST_URI} !(.*)/$

Please or to participate in this conversation.