Home > database >  how to remove index.php from the url in laravel
how to remove index.php from the url in laravel

Time:02-11

suppose my site open with the url https://www.example.com and it also opens with the https://www.example.com/index.php but i want it to open only with the https://www.example.com ONLY and not with https://www.example.com/index.php

just want to know how to remove index.php from my url

CodePudding user response:

Create a file .htaccess in your root directory and add the below code in .htaccess file.

<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>

CodePudding user response:

You can create a route with https://www.example.com/index.php that will redirect to user to https://www.example.com whenever user try to access https://www.example.com/index.php.

Eg. In you web.php file you can add a route like this.

Route::get('https://www.example.com/index.php', function () { 
    return redirect('https://www.example.com');
});
  • Related