IIS部署Laravel项目如何移除或隐藏URL路径中的index.php
IIS环境Laravel项目隐藏URL中index.php解决方案
前置检查
- 首先确认IIS已经安装URL Rewrite模块:打开IIS管理器,选中对应站点,在功能视图中查看是否存在「URL 重写」选项,若不存在需先安装该模块,安装完成后重启IIS服务。
- 回滚你之前的非常规修改:将
server.php改回原名称,删除项目根目录下手动复制的.htaccess文件,恢复项目原有目录结构。
配置重写规则
直接在站点指向的projectname/public目录下新建web.config文件,写入以下规则即可,不需要手动导入.htaccess(Apache规则转IIS规则经常出现转换错误):
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Laravel Rewrite" stopProcessing="true"> <match url="^(.*)$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" /> </rule> </rules> </rewrite> <directoryBrowse enabled="false" /> <defaultDocument> <files> <clear /> <add value="index.php" /> </files> </defaultDocument> </system.webServer> </configuration>
生效验证
- 保存
web.config后重启对应IIS站点 - 清空浏览器缓存后直接访问
localhost/projectname/homepage即可正常加载
内容的提问来源于stack exchange,提问作者HelloWorld
相关产品推荐
相关产品推荐

