0

Following a bug report in MAMP, initiated by another SO topic, I would like to ask how one would counter this bug where MAMP 3.0.6 (latest version) does not behave correctly with the following .htaccess rule :

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

should redirect anything like

http://localhost/foo/test/

to

http://localhost/foo/test

but redirects to

http://localhost/test/

instead.

Thanks, and kind regards !

Community
  • 1
  • 1
user3856210
  • 270
  • 2
  • 12
  • Are you setting a `RewriteBase` anywhere? If you are, what happens if you drop it, and if you're not, what happens if you set it to `/`? – Wrikken Sep 10 '14 at 01:22
  • I don't have have a rewrite base. I added the one you provided, but that didn't work, sorry :( – user3856210 Sep 10 '14 at 10:57

1 Answers1

0

Try this rule in your root .htaccess:

RewriteEngine On

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

Also keep in mind that if /foo/test is a real directory then trailing slash will be added by mod_dir unless you have DirectorySlash off in your .htaccess.

PS: This is tested on MAMP 3.0.2.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks for your reply :) Unfortunately, that didn't work. I have a simple folder in my MAMP directory that only contains a .htaccess and nothing else. Putting the above in the .htaccess does not change MAMP's behavior :/ – user3856210 Sep 10 '14 at 10:56
  • Then you're not setting it up right as it is working with exact same MAMP 3.0 on my side. Make sure you place it in `DocumentRoot/.htaccess` (not in any random folder). And do read what I mentioned below my rules also. – anubhava Sep 10 '14 at 10:59
  • What do you mean by DocumentRoot folder ? If I work on a project under "htdocs/test", would you consider "htdocs/test" as the root folder or "htdocs" ? I know this is a dumb question, but I'm just making sure we're talking about the same thing :) – user3856210 Sep 10 '14 at 11:01
  • `DocumentRoot` is set in your `Apache config`. Most likely it would be `htdocs` folder but better to check in `/Applications/MAMP/conf/apache/httpd.conf` file. – anubhava Sep 10 '14 at 11:08
  • Another way to check is to create a file called `info.php` with this code `` and then open `http://localhost/info.php` to check what is its `DOCUMENT_ROOT` value. – anubhava Sep 10 '14 at 11:16
  • I checked. DocumentRoot is `htdocs`. I placed a `.htaccess` in there with your code. No success :( I swear I'm trying my best ! – user3856210 Sep 10 '14 at 21:41
  • Well I have also tried my best. But your question/comments are not giving my any clue to help you further. – anubhava Sep 10 '14 at 22:05
  • It's alright, thanks for the time you spent helps, that was very nice of you :) I'll keep trying to find out what's not right and if I find I will update my question with the solution :) Thanks again ! – user3856210 Sep 15 '14 at 09:53