URL 重写

可以通过 URL 重写隐藏应用的入口文件 index.php,下面是相关服务器的配置参考:

更多使用方法,请访问手册

[ Nginx ]

  1. 在 nginx 虚拟主机 location 配置中添加规则,规则如下:

location / { // …..省略部分代码    
    if (!-e $request_filename) {        
        rewrite  ^(.*)$  /index.php?s=/$1  last;        break;   
    }
}

[ Apache ]

  1. httpd.conf 配置文件中加载了 mod_rewrite.so 模块

  2. AllowOverride None 将 None 改为 All

  3. 把下面的内容保存为.htaccess 文件放到应用入口文件的同级目录下

    Options +FollowSymlinks -MultiviewsRewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]

[ IIS ]

如果你的服务器环境支持 ISAPI_Rewrite 的话,可以配置 httpd.ini 文件,添加下面的内容:

RewriteRule (.*)$ /index\.php\?s=$1 [I]

在 IIS 的高版本下面可以配置 web.Config,在中间添加 rewrite 节点:

<rewrite>
    <rules> 
        <rule name="OrgPage" stopProcessing="true"> 
        <match url="^(.*)$" /> 
        <conditions logicalGrouping="MatchAll"> 
        <add input="{HTTP_HOST}" pattern="^(.*)$" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
        </conditions> 
        <action type="Rewrite" url="index.php/{R:1}" /> 
       </rule> 
    </rules> 
</rewrite>



THE END

本站部分文章搜集整理于互联网或者网友提供,如有侵权请联系站长

如若转载,请注明出处:https://www.htmlbk.com/badoucms/2546.html

温馨提示:该文档最后一次修改时间为2025-10-14 11:47:02,请注意相关的内容是否还可用!