如何强制 https 使用友好的 url 和 $_SERVER['REQUEST_URI']?

How to force https using friendly url with $_SERVER['REQUEST_URI']?

伙计们!

我在本地主机的 Apache2 上有一个 PHP 应用程序 运行ing。系统使用来自 $_SERVER['REQUEST_URI'] 的友好 URL。我的 .htaccess:

RewriteEngine On
#RewriteRule ^(.*)$ https://myapp.localhost/ [R=permanent]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?/ [QSA,L]

如果我注释第 3 行和第 4 行,系统 运行 可以。如果我按照我给你看的那样使用代码,他会把 URL 写成 https://myapp.localhost/index.php?/ where it needs to write https://myapp.localhost/。 SSL认证没问题。

使用此配置无法找到图像和存档,但没有第 3 行和第 4 行并手动使用 https 时显示。

感谢您的配合。

抱歉,@Martin 先生,我用葡萄牙语回复的最后一条消息。

也许问题出在使用了多个教程。经过这么多的搜索。我明白:有必要在 /etc/apache2/sites-available/bigpecasnew-localhost-ssl.conf 中删除一些代码行,并在我阅读时在 <Directory /home/user/site>SSLOptions +StdEnvVars</Directory> 中添加这些行 https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-18-04.

在我更改 .htaccess 上的代码后:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]

RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?/ [QSA,L]

这样就可以了。

感谢您的配合。