【问题标题】:Apache2 shows 404 error for sub links or path in laravelApache2 在 laravel 中显示子链接或路径的 404 错误
【发布时间】:2020-03-19 09:01:32
【问题描述】:

我在 Ubuntu 18.04 上将 apache2 用于 Laravel。当我使用域名时,它会显示 index.php 页面。但是当我单击子链接或路径时,它会显示 404 错误。

我正在使用this htaccess 教程

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

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/my-company-website/public


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

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

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin webmaster@localhost
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/my-company-website/public


    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>

/var/www/my-company-website/.htaccess

Options +FollowSymLinks -Indexes
RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

【问题讨论】:

    标签: laravel apache http-status-code-404


    【解决方案1】:

    尝试在 VirtualHost *:80 以及端口 VirtualHost *:433 标签内添加给定的目录标签,如下所示:

    <VirtualHost *:80>
             ..................
    
        <Directory /var/www/my-company-website/public>
              Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>
    
              .................
    </VirtualHost>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-04
      • 2018-10-04
      • 2013-07-01
      • 1970-01-01
      • 2018-01-18
      相关资源
      最近更新 更多