我设置了一个用于开发的本地Laravel服务器,并通过Git将更改推送到我的生产服务器。
我做了一个新的Laravel项目,我觉得不错。然后我在我的本地服务器上添加了php artisan make:auth并推送到生产环境,但是get 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这个建议。
有什么想法吗?谢谢。编辑: My 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>我删除了配置文件中的注释。
我试着添加
<Directory /var/www/html/Test/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>添加到我的000-default-le-ssl.conf,但它导致内部服务器错误..
发布于 2017-10-15 19:59:20
首先检查您的apache是否启用了mod_rewrite,可以通过输入以下命令轻松完成
apache2 -M或者更简单:
a2enmod rewrite如果你已经启用了它,你会收到消息:“模块重写已经启用”。
如果您没有,那么您将收到消息:“启用模块重写”。您必须重新启动apache。
检查您的htaccess线路中是否有(AllowOverride All)
<Directory /var/www/html/project/>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>发布于 2017-10-16 03:41:49
好了,我把它修好了。我的.htaccess文件中有一些问题。我从删除/Test/public中的.htaccess文件开始,然后在处理000-Default-le-ssl.conf文件时没有收到内部服务器错误。然后,我只是在目录中复制了另一个.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
RewriteCond %{REQUEST_URI} (.+)/$
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>如果任何人再次遇到此问题,请发布工作的.htaccess文件:)
https://stackoverflow.com/questions/46754393
复制相似问题