相关疑难解决方法(0)

如何使用NGINX从url中删除.php和.html扩展名?

我希望我的nginx make显示所有url的干净.

通过一些研究,我已经将第一个案例付诸实践.它通过以下配置完成:

location / {
    root   html;
    index  index.html index.htm index.php;
    try_files $uri.html $uri/ =404; 
}
Run Code Online (Sandbox Code Playgroud)

它适用于indexhtml.html显示为indexhtml,但.php没有任何反应.如果我将$ uri.html更改为$ uri.php,它既不适用于.html,也不适用于.php.我试图在php位置添加类似的东西,但没有任何成功.

有什么建议吗?

html php nginx

39
推荐指数
4
解决办法
5万
查看次数

如何在nginx中提供html文件,而不在此别名设置中显示扩展名

我在nginx中设置这个别名以正确显示我的网站时遇到了很多麻烦.

我关注的网站应该可以访问,mywebsite.com/mr并且与位于的网站不同mywebsite.com/.该网站位于/fullpath(为简单起见缩短)该网站需要提供三种内容:

  1. 索引文件位于/fullpath/index.html.
  2. 其他html文件(不在.html浏览器中显示扩展名).
  3. 静态资产(js/css/img)位于/fullpath和子目录中.

我已经尝试改变比赛的顺序,try_files并找到了他们都工作的情况,但不是在同一时间:

location /mr {
  default_type "text/html";
  alias /fullpath;

  # with this one 1 and 3 work
  # try_files $uri/index.html $uri.html $uri; 

  # with this one 2 and 3 work
  # try_files $uri $uri.html $uri/index.html;

  # with this one 1 and 2 work
  try_files $uri.html $uri/index.html $uri;
}
Run Code Online (Sandbox Code Playgroud)

当一个人不工作时404.有谁知道我怎么能正确地提供各种文件?

html alias nginx

20
推荐指数
2
解决办法
3万
查看次数

标签 统计

html ×2

nginx ×2

alias ×1

php ×1