请问,我在消除Laravel应用程序路由中的index.php文件时遇到了问题。我没有成功纠正它。当我使用服务器的IP地址一切正常但是当我使用子域名时它适用于/但对于其他路由或URL如/ login,我必须在它工作之前添加/index.php/login否则它不会。以下是我的服务器当前设置或配置的示例。
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
domain.com Apache CONF FILE(这个工作很棒)
<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>
test1.domain.com
/var/呜呜呜/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}]
第二个子域名APACHE CONF:
test2.domain.com /var/呜呜呜/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文件配置选项-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]
环境
Ubuntu 16.04
Server PHP 7.2
Laravel Version 5.4.30
所有这些的结果
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
请求
我需要获得在路线中使用index.php的需要。拜托,欢迎任何想法。也许新鲜的眼睛会帮助我找到解决这个问题的方法。
研究我已经尝试了以下链接。仍然很难找出错误,以便纠正。
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
再来一次。 FIX消除在Web APPLICATION ROUTE中包含index.php的需要。提前致谢
我能够解决这个问题。
第一:没有读取.htaccess文件。尽管我在上面做了所有这些,但是在我按照以下链接中的说明进行操作后,通过在.htaccess文件中放置乱码并且没有500状态错误显示来确认
.htaccess file not being read ("Options -Indexes" in .htaccess file not working)
但它仍然无法正常工作。我开始检查/ etc / apache2 / site-enabled目录中的所有文件并发现因为我在设置Laravel应用程序之前在我的服务器上安装了SSL加密,所使用的配置文件是由Encrypt为找到的域名
/etc/apache2/sites-enabled/test1.domain.com-le-ssl.conf(ssl - generated config)
/etc/apache2/sites-enabled/test1.domain.com.conf(普通配置)
和
/etc/apache2/sites-enabled/test2.domain.com-le-ssl.conf(ssl -generated config)
/etc/apache2/sites-enabled/test1.domain.com.conf(普通配置)
并且
/etc/Apache2/sites-enabled/domain.com-了-收视率.conf
/etc/Apache2/sites-enabled/domain.com.conf
所以我查看了文件并发现Document Root
指向了与目录不同的路径,这就是为什么htaccess文件没有被读取但是在我使用指向第二个子域的IP地址时被读取的原因
注意这是在SSL APACHE配置文件而不是正常的APACHE CONFIG文件DocumentRoot /var/www/test1.domain.com/public_html
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
在摘要中,这是修复它的最终更新示例
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin [email protected]
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>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/test1.domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test1.domain.com/privkey.pem
</VirtualHost>
</IfModule>
结果
我的路线和URL按预期工作。因为.htaccess文件现在正由适当目录中的apache正确读取
得到教训
这些是我所有这些的教训。希望其他人从中受益。谢谢。