0

I have a problem and I still can't fix that. I know that there are similars question here on SO, but nothing of that worked.

I use restful controllers. When I visit http://localhost/project/public/subsite it works. But when I visit http://localhost/project/public/subsite/ it redirects me to http://localhost/subsite

This is my current .htaccess file:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

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

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L] </IfModule>

I already tried solutions from these questions: laravel trailing Slashes redirect to localhost mod_rewrite remove trailing slash not working in Laravel

But the problem remains the same.

Community
  • 1
  • 1
namespace
  • 404
  • 3
  • 6
  • 18
  • _“This is my current htdocs file”_ – you mean `.htaccess` file, I suppose? And where is that `.htaccess` file located within your folder structure? – CBroe Jul 06 '14 at 22:25
  • Oh yeah sorry, I mean .htaccess file - it's stored in /project/public/ – namespace Jul 06 '14 at 22:55
  • That’s the problem then – when you configure rewriting in .htaccess context, the path to the directory of the .htaccess is already stripped off of the request URI when RewriteRules get to work – so your `^(.*)/$` only matches on `subsite/` in the first place. See if configuring a `RewriteBase` beforehand can fix that (not totally sure myself). – CBroe Jul 06 '14 at 23:00
  • I already did that like in the other questions mentioned I linked in my question but the problem remains. – namespace Jul 06 '14 at 23:01
  • why dont you have the webroot pointing to the public folder ? – lagbox Jul 06 '14 at 23:28
  • I can't. I'm not having the opportunity - easy said. – namespace Jul 06 '14 at 23:34
  • Well you could always try and simply give the path prefix `/project/public/` explicitly in your RewriteRule’s substitution part … – CBroe Jul 07 '14 at 06:21

2 Answers2

1
RewriteBase /project/public/

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

It worked for me to omit the slash that Cryode pointed to. Also be sure to clear your browser cache otherwise the changes may not take effect.

wizardofkoz
  • 111
  • 1
  • 3
0

Try adding a RewriteBase:

RewriteEngine on
RewriteBase /project/public/

Essentially, when you specify the beginning slash in your rewrite line:

#                   V----- This little guy
RewriteRule ^(.*)/$ /$1 [L,R=301]

It says "go to this URL, starting from the root". Since your root is http://localhost, it starts from there, not from your project's root.

Aken Roberts
  • 13,012
  • 3
  • 34
  • 40