0

另一个 SO 主题发起的MAMP 中的错误报告之后,我想问一下,如果 MAMP 3.0.6(最新版本)在以下 .htaccess 规则中无法正常运行,我将如何应对这个错误:

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

应该重定向任何东西

http://localhost/foo/test/

http://localhost/foo/test

但重定向到

http://localhost/test/

反而。

谢谢,亲切的问候!

4

1 回答 1

0

在您的根 .htaccess 中尝试此规则:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=302,L,NE]

还要记住,如果是一个真正的目录,那么除非你在你的 .htaccess 中,否则/foo/test将添加尾部斜杠。mod_dirDirectorySlash off

PS:这是在 MAMP 3.0.2 上测试的。

于 2014-09-10T06:07:38.183 回答