服务器去除 index.php 方法

ngnix服务器,进入:nginx/conf/vhosts.conf

server {
        listen       80;
        server_name  www.x.com x.com;
        root   "C:\Runing\PHPTutorial";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
        }
/** 添加的代码 *****/
        if (!-e $request_filename)
       {
          rewrite ^/(.*)$ /index.php?/$1 last;        break;
        }
/** 添加的代码 *****/
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

apache服务器,根目录添加 (.htaccess)文件,添加内容如下:

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

猜你喜欢

转载自www.cnblogs.com/qingsong/p/12198544.html