remove index.php from a specific url on Nginx server

依然范特西╮ 提交于 2020-01-06 20:34:50

问题


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.

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

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!!

Thanks

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.


回答1:


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

All I had to do is to force SSL to server https for index.php, and the changes were simple.

The original code was:

server {
  listen 80;
  server_name example.com;
  # normal http settings
  location /secure_area/ {
    return 301 https://$http_host$request_uri$is_args$query_string;
  }
}

And the changes I got is this:

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.



来源:https://stackoverflow.com/questions/22682298/remove-index-php-from-a-specific-url-on-nginx-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!