Laravel htaccess

前端 未结 5 730
逝去的感伤
逝去的感伤 2021-01-14 02:28

I\'ve setup a new install of Laravel on my local. It appears there are issues with htaccess or Apache settings. I\'ve researched for a number of hours and tried everything I

相关标签:
5条回答
  • 2021-01-14 02:46

    The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.

    If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:

    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    
    0 讨论(0)
  • 2021-01-14 02:49

    In the root path create a .htaccess file with

    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} !^/public/ 
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    
    
    
    RewriteRule ^(.*)$ /public/$1 
    #RewriteRule ^ index.php [L]
    RewriteRule ^(/)?$ public/index.php [L] 
    </IfModule>
    

    In public directory create a .htaccess file

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews -Indexes
        </IfModule>
    
        RewriteEngine On
    
        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]
    
        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
    

    if you have done any changes in public/index.php file correct them with the right path then your site will be live.

    what will solve with this?

    • Hosting issue of laravel project.
    • Css not work on laravel.
    • Laravel site not work.
    • laravel site load with domain/public/index.php
    • laravel project does not redirect correctly
    0 讨论(0)
  • 2021-01-14 02:57

    This solution worked fine, best solution ever for me. Paste this code into root htaccess. That's all. Leave all other files as they are

    <IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    
    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]
    
    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php
    </IfModule>
    
    0 讨论(0)
  • 2021-01-14 03:06

    Answer

    Heres what I found that worked. Delete the .htaccess file inside the /public directory and then put the following into the laravel installation's document root.


    Clarification

    So for clarification if your laravel application is installed at /public_html/laravel you will look inside /public_html/laravel/public and delete the .htaccess file there. Then inside the /public_html/laravel directory make a new file called .htaccess


    Copy the code below to a new .htaccess file in the doc root

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>
    
        RewriteEngine On
    
        # Redirect Trailing Slashes...
        RewriteRule ^(.*)/$ /public/$1 [L,R=301]
    
        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ public/index.php [L]
    </IfModule>
    

    Please note

    As Concordus Applications noted in their answer here make sure that the Loadmodule mod_rewrite is uncommented (make sure there is not a # symbol behind it in your apache config file)

    Concordus Applications also noted that you should have AllowOverride set to the appropriate setting. The example they gave was the following.

    <Directory "/some/absolute/path/htdocs">
        Options Indexes Includes FollowSymLinks MultiViews
        AllowOverride AuthConfig FileInfo
        Order allow,deny
        Allow from all
    </Directory> 
    

    Please make sure to restart your apache server if you made any changes to your apache config file.

    0 讨论(0)
  • 2021-01-14 03:07

    The accepted answer worked but not with laravel passport authentication.

    There is a need to add some header tweaking:

    RewriteEngine On
    
    RewriteCond %{HTTP:Authorization} ^(.+)$
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]
    
    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php
    
    0 讨论(0)
提交回复
热议问题