从Nginx服务器上的特定URL删除index.php
我在过去的几个小时中苦苦挣扎,试图找到一种不错的方法来从通过https提供的特定网址中删除 index.php .我要删除index.php的原因是,当通过https提供url时,它工作正常且没有问题.但是,当任何人在URL index.php的末尾键入时,可以将 https 更改为 http ,因此该URL上的SSL无效,因为加密信息可以.那样的话就不会做.
I was struggling last few hours tying to find a decent way to remove index.php from a specific url that is being served over https. The reason why I want to remove the index.php is that when a url is served over https it works fine and no issues. However, when any person type at the end of the url index.php, the https can be changed to http so the SSL is useless on that url as encrypted information can't be made in that case.
这是我之前为获得SSL工作而提出的问题,但这不包括通过https
This is the question I made before to get my SSL work, but that doesn't include the index.php being served over https My question about SSL for specific url
所以现在我有两个选择可以使用,但我不知道该如何选择.第一种是将index.php隐藏在通过https提供的URL上.第二种是对我在中使用的代码进行一些修改我之前的问题,因此即使在URL中键入index.php,也可以使用https.
so now I have two options to go with and I don't know how to go with them. The first is to hide index.php for the url that is being served over https. And the 2nd is to made some modification to that code I used in my previous question so that https can be used even if index.php is typed in the url.
任何帮助将不胜感激,因为我不知道如何在这里做任何事情!
any help would be appreciated since I have no clue how to do anything here!!
谢谢
更新:使用Nginx文件夹保护"auth_basic和auth_basic_user_file"时,我提供的解决方案似乎效果不佳.
Update: it doesn't seem that the solution I provided works well when Nginx folder protection "auth_basic and auth_basic_user_file" are used.
令人惊讶的是,我找到了一个解决方案.我有第2个选项可以使用,而不是第一个选项,因为我不得不进行很多努力来隐藏/删除index.php
surprisingly I found one solution out of the options I was after. I got the 2nd option to work, not the first one since I had a lot of struggle to force hiding / removing index.php
我要做的就是将SSL强制用于index.php的服务器https,并且更改很简单.
All I had to do is to force SSL to server https for index.php, and the changes were simple.
原始代码为:
server {
listen 80;
server_name example.com;
# normal http settings
location /secure_area/ {
return 301 https://$http_host$request_uri$is_args$query_string;
}
}
我得到的改变是这样:
server {
listen 80;
server_name example.com;
# normal http settings
location ~* ^/secure_area/ {
return 301 https://$http_host$request_uri$is_args$query_string;
}
}
所以更改是从位置/到位置〜* ^/
so the change was from location / to location ~* ^/
我希望这对遇到此问题的任何人都是有用的.
I hope it is going to be useful for anyone run into this issue.