Support the ongoing development of Laravel.io →
Configuration Requests Forms
Last updated 2 years ago.
0

What happens when you try to access your website but you add an index.php to the end of it?

localhost/public/index.php?

It has to be an htaccess issue or at the very least you can solve that issue by adding something to htaccess. If that doesn't come up with any results try this..

<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]
    
    ## EXPIRES CACHING ##
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresDefault "access 1 month"
    </IfModule>
    ## EXPIRES CACHING ##
</IfModule>

and then try to just access the site without the index.php.

Last updated 2 years ago.
0

Site root is at localhost/project1

Then If I type localhost/project1 , it becomes localhost/project1/

If I add index.php, it goes to the same page as if without it.

I discovered the problem when I printed url() in form action, that become localhost/project1, without the slash, and when I click it, the submit goes back to the form page instead of going to the post place.

I could of course concatenate the extra slash in the form action url, but I have a bad feeling that this might be a big problem when the code gets more complicated.

This issue happens only when using apache alias pointing to a folder. Without folder, the slash gets not added.

Last updated 2 years ago.
0

repeater09 said:

What happens when you try to access your website but you add an index.php to the end of it?

localhost/public/index.php?

It has to be an htaccess issue or at the very least you can solve that issue by adding something to htaccess. If that doesn't come up with any results try this..

<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]
   
   ## EXPIRES CACHING ##
   <IfModule mod_expires.c>
   ExpiresActive On
   ExpiresByType image/jpg "access 1 year"
   ExpiresByType image/jpeg "access 1 year"
   ExpiresByType image/gif "access 1 year"
   ExpiresByType image/png "access 1 year"
   ExpiresByType application/pdf "access 1 month"
   ExpiresByType text/x-javascript "access 1 month"
   ExpiresByType application/x-shockwave-flash "access 1 month"
   ExpiresByType image/x-icon "access 1 year"
   ExpiresDefault "access 1 month"
   </IfModule>
   ## EXPIRES CACHING ##
</IfModule>

and then try to just access the site without the index.php.

Like. I copied this into my htaccess and tested. Nothing different happened - the final slash keep beeing added in the end of url.

Last updated 2 years ago.
0

I mentioned it only happens with folders ? With plain url the slash doesn't get added. I think it's related to folder security and slash is forced by apache to prevent it from displaying the folder files ( which happens if we remove the slash ).

Anyone can sucessfully run laravel app in a folder other than plain domains ?

[]s

Last updated 2 years ago.
0

I am having this problem as well, and this appending trailing slash 301 redirect, I suspect, is causing problem with my browser-sync, making it unable to inject browser-sync client script. I am trying to mix Angular with Laravel in a good way. My first request to server looks like:

localhost/folder

The server somehow automatically redirects to

locahost/folder/

This not-sure-error-or-feature appears when I use the Laravel Bootstrap Starter site https://github.com/andrewelkins/Laravel-4-Bootstrap-Starter-Site/

When I switch back to using the bare bone Laravel App at https://github.com/laravel/laravel, there is no such 301 redirect.

Tried to change .htaccess back and forth, the 301 redirect is still there. I think it is due to some dependencies in the Starter Site app.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.