网站去除index.php尾巴方法
2025-04-16 15:33:42

【IIS服务器】

查看服务器的网站根目录下是否有web.config文件,将红色代码添加<system.webServer>与</system.webServer>之间。如果没有web.config文件,就将全部代码保存为web.config文件,上传到网站根目录下,记得去后台清除缓存,再从网站首页访问哦!

<?xmlversion="1.0"encoding="UTF-8"?>

<configuration>

<system.webServer>

<rewrite>

<rules>

<rulename="OrgPage"stopProcessing="true">

<matchurl="^(.*)$"/>

<conditionslogicalGrouping="MatchAll">

<addinput="{HTTP_HOST}"pattern="^(.*)$"/>

<addinput="{REQUEST_FILENAME}"matchType="IsFile"negate="true"/>

<addinput="{REQUEST_FILENAME}"matchType="IsDirectory"negate="true"/>

</conditions>

<actiontype="Rewrite"url="index.php/{R:1}"/>

</rule>

</rules>

</rewrite>

</system.webServer>

</configuration>

 

【Nginx服务器】

在原有的nginx重写文件里新增以下代码片段:

location/{

  if(!-e$request_filename){

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

    break;

  }

}

如果是安装在二级目录下,请复制以下代码:

location/二级目录名/{

  if(!-e$request_filename){

    rewrite^/二级目录名/(.*)$/二级目录名/index.php?s=/$1last;

    break;

  }

}

如果类似阿里云空间,一个虚拟主机的根目录与二级目录都安装了易优,那么设置如下:

location/{

  if(!-e$request_filename){

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

    break;

  }

}

location/二级目录名/{

  if(!-e$request_filename){

    rewrite^/二级目录名/(.*)$/二级目录名/index.php?s=/$1last;

    break;

  }

}

【apache服务器】易优cms在apache服务器环境默认自动隐藏index.php入口。如果发现没隐藏,可以检查根目录.htaccess是否含有以下红色代码段:

<IfModulemod_rewrite.c>

Options+FollowSymlinks-Multiviews

RewriteEngineon#http跳转到https#RewriteCond%{HTTPS}!=on#RewriteRule^(.*)$https://%{SERVER_NAME}/$1R,L 

RewriteCond%{REQUEST_FILENAME}!-d

RewriteCond%{REQUEST_FILENAME}!-f

RewriteRule^(.*)$index.php?s=/$1QSA,PT,L

</IfModule>如果还是没有隐藏,可以尝试把红色第四行的代码改为加上个问号试试:  RewriteRule^(.*)$index.php?/$1QSA,PT,L或者修改为:RewriteRule^(.*)$index.php/$1QSA,PT,L如果还是不行,继续查看apache是否开启了URL重写模块rewrite_module,然后重启服务就行了。 

(作者:镜头)