用户
 找回密码
 入住 CI 中国社区
搜索
查看: 4604|回复: 4
收起左侧

[初级] IIS 如何让链接去掉index.php 优化url

[复制链接]
发表于 2016-11-22 15:50:41 | 显示全部楼层 |阅读模式
无非是配置 web.config文件
如我们有一个域名:www.123.com
1.在根目录创建一个 web.config 文件
2.在里面添加XML代码:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="已导入的规则 1">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{R:1}" pattern="^(index\.php|cs\.php|images|css|js|data|video|application|robots\.txt)" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:1}" />
                </rule>
                <rule name="已导入的规则 2" stopProcessing="true">
                    <match url=".?" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^([a-z.]+)?123\.com$" />
                        <add input="{HTTP_HOST}" pattern="^www\." negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://www.123.com{URL}" appendQueryString="true" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>


已导入的规则 1 :里面  <add pattern=" 你的文件夹及文件名,文件的时候有后缀用 \ 如:hh\.txt  " />
已导入的规则 2 : 将里面的链接 123.com      www.123.com  改成你的就可以了

没错就那么简单!!!
不会可以下载附件放到你的网站根目录就可以了


web.zip

615 Bytes, 下载次数: 14

评分

参与人数 1威望 +5 收起 理由
Hex + 5 赞一个!

查看全部评分

发表于 2016-11-22 18:09:15 | 显示全部楼层
这个需要安装IIS_Rewrite吧!
我用的是这个:
XML复制代码
 
                        <!-- 去掉CI的index.php入口文件,显示友好Url -->
                        <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>
 
复制代码

 楼主| 发表于 2017-2-14 14:14:03 | 显示全部楼层
happynetlife 发表于 2016-11-22 18:09
这个需要安装IIS_Rewrite吧!
我用的是这个:

发表于 2017-3-10 20:55:31 | 显示全部楼层
楼主我用你的方法确实可以去掉index.php可是去掉后,页面的样式和图片都显示不出来了,应该是样式引用路径出错了,可是不会改,求指教
 楼主| 发表于 2017-3-21 14:22:39 | 显示全部楼层
无痕_g3swS 发表于 2017-3-10 20:55
楼主我用你的方法确实可以去掉index.php可是去掉后,页面的样式和图片都显示不出来了,应该是样式引用路径出 ...

比如你的图片链接是:www.xxxxxx.com/xxx/123.jpg
你可以 <?= base_url('xxx') ?>/123.jpg

本版积分规则