【问题标题】:laravel all urls 404 without index.phplaravel 没有 index.php 的所有 url 404
【发布时间】:2019-01-29 12:51:24
【问题描述】:

一切正常,包括浏览器上的 HTTP 到 https 重定向

http://example.com/app/login  404
https://example.com/app/login 404
http://www.example.com/app/login 404
https://www.example.com/app/login 404

http://example.com/index.php/app/login  OK
https://example.com/app/index.php/login OK
http://www.example.com/index.php/app/login OK
https://www.example.com/index.php/app/login OK

使用邮递员测试的网址

http 到 https 的重定向适用于 www 或非 www

服务器 Ubuntu 18.04 阿帕奇 2.4.29

/etc/hosts  

 206.189.85.* example.com #server ip address
 206.189.85.* www.example.com
 127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

/etc/apache2/sites-available/example.com.conf

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/example.com/public

    <Directory /var/www/example.com/public/>
        Options -Indexes +FollowSymLinks +MultiVies
        AllowOverride All      
        Require all granted     
     </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    LogLevel warn
</VirtualHost>

/etc/apache2/sites-available/example.com-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin admin@example.com
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/example.com/public

    SSLEngine On

    <Directory /var/www/html/example.com/public/>
        Options Indexes FollowSymLinks
        AllowOverride All       
        Require all granted
     </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
</IfModule>

.htaccess 内容

DirectoryIndex index.php
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>


    RewriteEngine On



    RewriteCond %{HTTPS} off   
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteRule .? %{ENV:BASE}/index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

</IfModule>

【问题讨论】:

    标签: laravel apache .htaccess ubuntu laravel-5


    【解决方案1】:

    将目录索引和重定向永久添加到您的虚拟主机:80

    <VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName www.example.com
    ServerAlias example.com
    DirectoryIndex index.php
    DocumentRoot /var/www/example.com/public
    Redirect permanent / https://www.example.com/
    
    <Directory /var/www/example.com/public/>
        Options -Indexes +FollowSymLinks +MultiVies
        AllowOverride All      
        Require all granted     
     </Directory>
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    LogLevel warn
    </VirtualHost>
    

    【讨论】:

    • Http 到 https 重定向工作正常,唯一的问题是 url 中的 index.php
    • 尝试添加 conf 并在 htaccess 中重新启用 conf 但错误仍然存​​在。
    • 你能发布 htaccess 的内容吗
    【解决方案2】:

    检查清单

    1. 你的 apache a2enmod 重写启用了吗?

      启用命令

      sudo a2enmod 重写

      sudo service apache2 重启

    2. 在.htaccess 末尾添加这一行

      重写规则。 ^ index.php [L]

      查看此线程以获取更多信息 Thread

    【讨论】:

      【解决方案3】:

      你能改变吗 RewriteRule .? %{ENV:BASE}/index.php [L]RewriteRule ^ index.php [L]

      编辑:

      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)/$ /$1 [L,R=301]
      
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ index.php [L]
      

      你能检查一下这个重写规则吗?如果工作,请稍后添加您的 https 和身份验证条件。

      【讨论】:

      • 没有帮助,问题仍然存在
      猜你喜欢
      • 2014-03-04
      • 1970-01-01
      • 1970-01-01
      • 2017-03-09
      • 2014-12-08
      • 2016-05-20
      • 2016-09-21
      • 2019-04-21
      • 2013-04-30
      相关资源
      最近更新 更多