如何解决如何通过$ _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]
那行得通。
谢谢您的合作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。