I have a server with a web application developed in laravel, I am trying to configure the .htaccess file so that, if a URL is entered with index.php
, it disappears.
I am currently using these lines:
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
This makes:
- if the URL comes as
midominio.com/index.php/home
- becomes
midominio.com/home
The problem (and consequently an error) is:
- when a URL like this comes:
midominio.com/index.php
- transforms the url to:
midominio.com/var/www/Proyecto/public
If I use this in the .htaccess
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^index.php(.*)$ $1 [R=301,L]
This last error is corrected, but it does not replace the index.php
of the URL. If I put the two solutions is fixed, but I would like to know if there is a solution that brings these two alternatives together.
Examples:
I need the URL how are you
midominio.com/index.php/loQueSea
midominio.com/index.php
Modify to:
midominio.com/loQueSea
.htaccess complete
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
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}]
#Se saca el index.php
#RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.+/)?index\.php(?:/(.*))?$ $1$2 [R=301,NC,L]
</IfModule>