1

I did try lots of solution from different resources like GitHub, StackOverflow, etc, but didn't get the solution to remove index.php from url in laravel 5.8 version. This issue occurs only in version 5.8

Here is my .htacess file code. Which is placed on root directory:

DirectoryIndex index.php
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteBase /laravel/portal/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]

</IfModule> 

If somebody has a solution. Please let me know

PHP Ninja
  • 1,020
  • 1
  • 9
  • 27
  • 1
    The Laravel documentation has a section [Web Server Configuration](https://laravel.com/docs/5.8#web-server-configuration). Have you tried that? – brombeer Apr 25 '19 at 06:17
  • Possible duplicate of [How Can I Remove “public/index.php” in the URL Generated Laravel?](https://stackoverflow.com/questions/23837933/how-can-i-remove-public-index-php-in-the-url-generated-laravel) – emix Apr 25 '19 at 06:23
  • @emix please check version of laravel which i mentioned – PHP Ninja Apr 25 '19 at 06:24
  • It doesn't matter which framework you use. Those solutions apply to any framework, let it be Laravel, Symfony, Zend, you name it. – emix Apr 25 '19 at 06:25
  • @emix I did work with the older version of laravel but I did face this issue only with 5.8 – PHP Ninja Apr 25 '19 at 06:29
  • Can you please show directory structure ? – Vipertecpro Apr 25 '19 at 11:08
  • @ViperTecPro Thanks for asking but i got my solution – PHP Ninja Apr 25 '19 at 11:25
  • Could you please tell us how did you managed to resolve it, it will help us learn :) – Vipertecpro Apr 25 '19 at 11:26
  • Check this link https://gist.github.com/Guley/6b114d33eb7420a0a07d58670d965a8c and i also added answer related to it – PHP Ninja Apr 25 '19 at 11:28

2 Answers2

0

You must have mod_rewrite enable on your Apache server. The rewrite module is required to apply these settings. You also have enabled .htaccess.

<IfModule mod_rewrite.c>
  RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Rakesh Jakhar
  • 6,298
  • 2
  • 9
  • 20
0

I Got the solution. Thanks for your help.

In order to use mod_rewrite you can type the following command in the terminal:

sudo a2enmod rewrite

Restart apache2 after

sudo systemctl restart apache2

Here is root directory .htaccess file:

<IfModule mod_rewrite.c>
  Options +FollowSymLinks -Indexes
RewriteEngine On

RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
PHP Ninja
  • 1,020
  • 1
  • 9
  • 27