如何通过$ _SERVER ['REQUEST_URI']强制使用友好的URL?

问题描述

人们!

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

RewriteEngine On
#RewriteRule ^(.*)$ https://myapp.localhost/$1 [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?/$1 [QSA,L]

如果我在第3行和第4行添加注释,则系统运行正常。如果我使用显示的代码,他将URL写为https://myapp.localhost/index.php?/,并在其中写https://myapp.localhost/。通过SSL认证没关系。

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

谢谢您的合作。

解决方法

对不起,我用葡萄牙语回答的最后一封信@马丁先生。

也许问题出在使用多个教程。经过如此多的搜索。我了解:有必要在/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?/$1 [QSA,L]

那行得通。

谢谢您的合作。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...