Please, I have been having issues with eliminating index.php file in the routes for my Laravel applications. I have not had success rectifying it. When I use the server's IP address everything works fine but when I use the sub-domain names it works for / but for other routes or URL like /login, I must add /index.php/login before it works otherwise it doesn't. Below is a sample of my server current settings or configurations.
Site Works when index.php is used in the URL
Site doesn't work when index.php is removed from the Url
But it works well when i use the IP address directly.
but in this case it serves the laravel application hosted in the second subdomain. I just don't know why
MAJOR SITE
domain.com
Apache CONF FILE (This Works Great Already)
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/public_html
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.domain.com [OR]
RewriteCond %{SERVER_NAME} =domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
FIRST SUBDOMAIN SITE APACHE CONF:
test1.domain.com
/var/www/test1.domain.com/public_html
// APACHE CONF FILE
/etc/apache2/sites-available/test1.domain.com.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName test1.domain.com
ServerAlias www.test1.domain.com
DocumentRoot /var/www/test1.domain.com/public_html
<Directory /var/www/test1.domain.com/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
RewriteEngine on
RewriteCond %{SERVER_NAME} =test1.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
//.htaccess for test1.domain.com
IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# 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}]
SECOND SUB-DOMAIN SITE APACHE CONF:
test2.domain.com /var/www/test2.domain.com/public_html
/APACHE CONF FILE /etc/apache2/sites-available/test2.domain.com.conf
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName test2.domain.com
ServerAlias test2.domain.com
DocumentRoot /var/www/test2.domain.com/public_html
<Directory /var/www/test2.domain.com/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
RewriteEngine on
RewriteCond %{SERVER_NAME} =test2.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
.htaccess
test2.domain.com htacess file config Options -MultiViews -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# 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]
Environment
Ubuntu 16.04
Server PHP 7.2
Laravel Version 5.4.30
OUTCOME OF ALL THESE
domain.com //WORKS
test1.domain.com // WORKS
but test1.domain.com/login // Does'nt work
instead test1.domain.com/index.php/login // works
test2.domain.com // WORKS
but test2.domain.com/login // Does'nt work
instead test2.domain.com/index.php/login // works
but I realized that
the Ip address works well without the need for index.php
http://server-ip-address // works but serves the app in test2.domain.com
http://server-ip-address/login // also Works well which is what I expect in the two subdomain test1.domain.com and test2.com
REQUEST PLEASE
I need TO GET RID OF THE NEED TO USE index.php in the route. Please, Any Idea is welcome. Perhaps fresh Eyes would help me identify ways to fix this out.
RESEARCH I HAVE made I Have tried the following links already. still having a hard time finding out what is wrong so that it is rectified.
htaccess for domain and subdomain with laravel htaccess for domain and subdomain with laravel
apache virtual host and "Dynamic" Domains
Setting document root for Laravel project on Apache virtual host apache virtual host and "Dynamic" Domains
ONCE AGAIN. FIX To Eliminate the need to include index.php in the Web APPLICATION ROUTE. THANKS IN ADVANCE