2

Behavior

If I go to: http://localhost/login
... everything works as acceptected

If I go to: http://localhost/login/
.. I get redirected to: http://localhost/var/www/public/login

Expected behavior is for the trailing slash to be removed:
http://localhost/login/ =>> http://localhost/login

.htaccess:

RewriteEngine On

RewriteRule (.+)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Question

  1. Why doesn't it work as expected?
  2. How do I make it work as expected?
4

1 回答 1

0

试试这个规则来删除斜杠(使用非贪婪的正则表达式):

RewriteRule ^(.+?)/$ $1 [L,R=301]

您的示例可能没有任何问题。尝试清除缓存,它应该可以工作..

于 2013-11-01T12:58:44.003 回答