DWQA QuestionsHow to Remove public from URL and remove index.php from URL in laravel ? Step by step solution.
asked 6 years ago

Solution :
Step1 : open public folder and copy index.php
step2 : Paste index.php to root of your laravel folder (suppose your laravel folder name is laravel_project, just put file on root)
Step3 : open index.php
Step4 : Replace the following line 
require __DIR__.’/../bootstrap/autoload.php’;  to  require __DIR__.’/bootstrap/autoload.php’;
$app = require_once __DIR__.’/../bootstrap/app.php’;  to $app = require_once __DIR__.’/bootstrap/app.php’;
Step4 : Save your file and check , you will be run your application without public in URL
Now How to remove index.php
Step1 : create .htaccess file on your laravel root folder
Step2 : Open  .htaccess file
Step3 : Copy and paste following code to .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>
Step5 : Save and exit 
Note : make sure that mod_rewrite should enable in your apache module, to enable visit link 
Step6 : check now you will able access all route without index.php
for more info write us mail : [email protected]
 
Thanks 🙂