nginx - How to use re-rules to remove .php from URL
PHPz
PHPz 2017-05-16 17:03:43
0
1
966

ThinkPHP How to use Apache and Nginx to rewrite rules when REWRITE mode is turned on,
Remove .php
in http://www.example.com/api.php/user/info/1880233 Becomes http://www.example.com/api/user/info/1880233

Looking for examples of rewrite rules for apache and nginx.

PHPz
PHPz

学习是最好的投资!

reply all(1)
过去多啦不再A梦

Sorry, I didn’t see the question clearly before

Nginx:

location ~ .php {
  fastcgi_pass   127.0.0.1:9000;  #根据实际情况修改
  fastcgi_index  index.php;
  include        fastcgi_params;

  #这一段是让 Nginx 支持 PATH_INFO
  set $real_script_name $fastcgi_script_name;
  if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {
      set $real_script_name ;
      set $path_info ;
  }
  fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
  fastcgi_param SCRIPT_NAME $real_script_name;
  fastcgi_param PATH_INFO $path_info;
}

location / {
  if (!-e $request_filename) {
    rewrite ^/api/(.*)$ /api.php/ last;
    break;
  }
}

Apache:
Still refer to the introduction in this link: http://doc.thinkphp.cn/manual/url_rewrite.html
But change the code to the following:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/api/(.*)$ api.php/ [QSA,PT,L]
</IfModule>

And put the .htaccess file into the api.php folder

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template