【发布时间】:2017-10-15 11:12:28
【问题描述】:
我为开发设置了一个本地 Laravel 服务器,并通过 Git 将更改推送到我的生产服务器。
我做了一个新的 Laravel 项目,我认为它没问题。然后我在我的本地服务器上添加了 php artisan make:auth 并推送到生产但得到 404 找不到登录(或注册)。经过一番工作,我发现: www.mySite.com/login 找不到但如果我写 www.mySite.com/index.php/login 它可以工作。
所以现在我想我必须修改我的 htaccess 以忽略 index.php 但我无法让它工作。我尝试了一些建议,但似乎都不起作用,我不知道为什么它不起作用。
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase Test/public/
* RewriteCond %{THE_REQUEST} /index\.php [NC]
* RewriteRule ^(.*?)index\.php$ /$1 [L,R=302, NC, NE]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^(.*)/$ /$1 [L,R=301]
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}]
</IfModule>
标有 * 的两行是我在阅读 Stack Overflow 上的建议后尝试添加的(现在找不到链接)。我也试过 htaccess remove index.php from url 这个建议。
有什么想法吗?谢谢。 编辑: 我的 sites-enabled/000-default.conf 如下所示:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/Test/public
<Directory /var/www/html/Test/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} =nfoscan.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
而我的 000-default-le-ssl.conf 看起来像这样:
<IfModule mod_ssl.c>
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/Test/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ServerName mysite.com
</VirtualHost>
</IfModule>
我删除了配置中的 cmets..
我尝试添加
<Directory /var/www/html/Test/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
到我的 000-default-le-ssl.conf 但它导致内部服务器错误..
【问题讨论】:
标签: php apache laravel .htaccess authentication