【发布时间】:2019-02-07 03:10:38
【问题描述】:
请,我在删除 index.php 文件时遇到了问题 我的 Laravel 应用程序的路由。 我没有成功纠正它。当我使用服务器的 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
主要网站
域名.com
Apache CONF 文件(这已经很好用了)
<VirtualHost *:80>
ServerAdmin admin@domain.com
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>
第一个子域站点 APACHE 会议:
test1.domain.com
/var/www/test1.domain.com/public_html
// APACHE 配置文件
/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>
//test1.domain.com 的.htaccess
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 会议:
test2.domain.com /var/www/test2.domain.com/public_html
/Apache 配置文件 /etc/apache2/sites-available/test2.domain.com.conf
<VirtualHost *:80>
ServerAdmin admin@test2.domain.com
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 应用程序路径中包含 index.php 的需要。提前致谢
【问题讨论】:
标签: php laravel apache .htaccess vps