'Remove index.php from URL of Laravel
I am using Laravel 5.5.12 in Linux Mint.I am using LAMP stack. I would like to remove index.php
from URL. My mod_rewrite
apache module enabled.
My .htaccess
file located in public
folder and it contains following code.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
# 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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I renamed the server.php in the Laravel root folder to index.php and copy the .htaccess file from /public directory to Laravel root folder. But it is not working.
I placed below code in .htaccess
file
<IfModule mod_rewrite.c>
# Turn Off mod_dir Redirect For Existing Directories
DirectorySlash Off
# Rewrite For Public Folder
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
But this not working.
Could anyone help me in this regard ?
Solution 1:[1]
Reset anything you have changed back to the default.
In your apache virtual host configuration, ensure you have the DocumentRoot correct (it will be something like /var/www/html/laravelproject/public).
You should not need to make any changes to the .htaccess file in the public folder as this handles rewriting the url to remove index.php. However, in some environments, I have had to add
RewriteBase /laravelproject
to the .htaccess in the public folder.
Solution 2:[2]
I found the answer here:
https://ma.ttias.be/remove-index-php-from-the-url-in-laravel/
To summarise, I added the following to the .htaccess file, directly below the existing index.php entry:
RewriteRule ^index.php/(.+) /$1 [R=301,L]
Solution 3:[3]
Go to httpd.conf
file, search for the line DocumentRoot
and change it to where ever your index.php
is. For example:
DocumentRoot "C:/xampp/htdocs/myappfolder/public"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | kerrin |
Solution 2 | Relaxing In Cyprus |
Solution 3 | Alireza Bijantabar |