index.php is a valid file in the public directory; any file in the public directory is publically accessible.
Mar 25, 2020
7
Level 5
laravel app using index.php in url
I have a website in laravel which is installed on a vps server using apache.
The virtualhost file for it is:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public
<Directory /var/www/example.com/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
The problem that i discovered today is if i use in the url /index.php it still loads the homepage (even if I don`t have that route defined)
the homepage route is:
Route::any('/', 'HomeController@index')->name('homepage')
Why is this happening? Is there a setting in laravel to prevent this ?
Level 5
I have edited using QSD:
# Redirect if index.php is in the URL
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php / [R=301,NE,L,QSD]
And now it works :)
Please or to participate in this conversation.