2017-10-15 141 views
0

我设置了一个本地Laravel服务器进行开发,并通过Git将更改推送到我的生产服务器。Laravel auth not working将mysite.com/index.php改为mysite.com

我做了一个新的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 这个建议。

任何想法?谢谢。 编辑: 我启用的站点 -/000-default.conf看起来是这样的:

<VirtualHost *:80> 


     ServerAdmin [email protected] 
     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默认-LE-ssl.conf中是这样的:

<IfModule mod_ssl.c> 
<VirtualHost *:443> 
     # The ServerName directive sets the request scheme, hostname and port that 


     ServerAdmin [email protected] 
     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> 

我删除了在CONFIGS评论..

我尝试添加

<Directory /var/www/html/Test/public> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride All 
      Require all granted 
     </Directory> 

我000违约乐-ssl.conf但它导致内部服务器错误..

回答

0

首先检查你的Apache已经启用了mod_rewrite您可以通过 轻松完成输入

apache2 -M 

或更简单:

a2enmod rewrite 

如果你已经启用它,你会收到消息: “模块重写已启用”

如果你还没有那么你会l接收消息: “启用模块重写”。你将不得不重新启动Apache。

检查,如果你有你的htaccess线(所有的AllowOverride)

<Directory /var/www/html/project/> 
    Options FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow,deny 
    allow from all 
</Directory> 
+0

嗨,即时通讯非常新的Apache和Apache配置..我编辑我的问题与Apache配置文件..我认为问题是000-default-le-ssl .conf但我不知道如何改变它使其工作(请参阅我的编辑)。 /谢谢:) – hybris

+0

你有htaccess的: 'SSLEngine的on' 您也可以在Apache日志搜索错误: '/无功/日志/的Apache2/error_log' – Rafael

+0

在我的000默认-LE-SSL。 conf我可以将DocumentRoot设置为/ var/www/html或/ var/www/html/Test/public,并且两者都可以正常工作......但是当我混淆了时,只有工作正常给内部服务器错误? – hybris

0

好了,所以我固定它。我的.htaccess文件存在一些问题。我开始删除/ Test/public中的.htaccess文件,然后在000-Default-le-ssl.conf文件中搞乱时,我没有得到内部服务器错误。然后,我只是在目录中的另一个.htaccess文件中复制,它的工作原理是:O

感谢所有试图帮助我的人!

<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文件,如果有人再次有这个问题:)