怎样在nginx 中使用.haccess

在nginx 中使用.haccess是个伪命题,因为haccess是apache支持的配置文件,但是这个文件不能在nginx当中使用,需要你使用自定义的conf文件。

You can’t do this. You shouldn’t. If you need .htaccess, you’re probably doing it wrong.

在nginx conf配置文件中加入

 

server {
      listen 80;
      listen 443 ssl http2;
      server_name ydh.szsczx;
      root "/home/vagrant/Code/site";

    #必须使用绝对路径 
    include /home/vagrant/Code/site/dsc-nginx.conf;
........
}

示例:dsc-nginx.conf文件内容

if (!-e $request_filename)
{
rewrite ^/index.html$ /index.php last;
rewrite ^/mobile/category/([0-9]+)$        /mobile/index.php?m=category&id=$1 last;
}

  

原文地址:https://www.cnblogs.com/fogwang/p/12714362.html