nginx 隐藏index.php 并开启rewrite日志调试,apache也有

开启rewrite 日志

error_log /data/log/nginx/error.log notice;

位于最外层,大约在文件的前几行

再在http{}括号里增加一行:rewrite_log on;

重写的日志将写入/data/log/nginx/error.log

关键代码

在http{ server{ location {#代码处} }}里写代码

location / {

  if ( !-e $request_filename ) {

    rewrite ^/(.*)$ /index.php?s=$1 last;

    break;

  }

}

若有ask目录则:

location /ask/ {

  if ( !-e $request_filename ) {

    rewrite ^/(.*)$ /ask/index.php?s=$1 last;

    break;

  }

}

location的顺序与执行顺序无关

php代码获取$_GET['s']代码

nginx.conf格式

...

events{

}

http{

  upstream xxx{



  }

  server {

    location {

      if () {



        }
    }
  }

}

apache 的重写规则

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index\.php?s=$1 [QSA,PT,L]
#QSA意味着,如果有一个与原始URL查询字符串传递,它将被附加到重写(olle?p=1将被重写为index.php?url=olle&p=1。
#L意味着如果规则匹配,不处理任何更多RewriteRules下面这一个。
#PT(pass through to next handler) 传递给下一个处理