Laravel Apache2 Https 没有漂亮的 URL

发布于 2025-01-09 00:47:13 字数 2225 浏览 2 评论 0原文

我在新服务器上安装了 laravel,使用 certbot 安装了新的 HTTPS 证书,但漂亮的 url 不起作用。

通过HTTP没有问题,但是一旦我访问HTTPS,mod_rewrite似乎不起作用

这是apache HTTP配置

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName mydomain.it
    DocumentRoot /var/www/example-app/public

    <Directory /var/www/example-app/public>
    Options Indexes MultiViews
    AllowOverride None
    Require all granted
    </Directory>

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

</VirtualHost>

Questa la configurazione HTTPS:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName mydomain.it
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/example-app/public


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

        # For most configuration files from conf-available/, which are
        <Directory /var/www/example-app/public>
            Options Indexes MultiViews
            AllowOverride None
            Require all granted
         </Directory>


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

我还附加了htaccess,但它是laravel的默认值:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On


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

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

I installed laravel on a new server, with certbot I installed a new HTTPS certificate but the pretty urls don't work.

Via HTTP there are no problems, but as soon as I access HTTPS it seems that mod_rewrite does not work

This is the apache HTTP configuration

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName mydomain.it
    DocumentRoot /var/www/example-app/public

    <Directory /var/www/example-app/public>
    Options Indexes MultiViews
    AllowOverride None
    Require all granted
    </Directory>

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

</VirtualHost>

Questa la configurazione HTTPS:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName mydomain.it
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/example-app/public


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

        # For most configuration files from conf-available/, which are
        <Directory /var/www/example-app/public>
            Options Indexes MultiViews
            AllowOverride None
            Require all granted
         </Directory>


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

I also attach htaccess but it is the default of laravel:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On


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

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

送舟行 2025-01-16 00:47:13

更改 VirtualHost 中的默认 ssl 配置文件解决问题:

<Directory /var/www/example-app/public>
   AllowOverride all
 </Directory>

Change the default ssl configuration file in VirtualHost resolve the problem:

<Directory /var/www/example-app/public>
   AllowOverride all
 </Directory>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文