有人问我http如何设置跳转到https,他自己百度了一下得到的IIS设置伪静态代码集合极致CMS的伪静态如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="OFF" ignoreCase="true" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> <system.webServer> <rewrite> <rules> <rule name="allow_rules" enabled="true" stopProcessing="true"> <match url="^(.*)$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
上面两种伪静态合并的方式不对,他说可以访问首页,没有报错我也感觉有些奇怪。但是其他页面访问都是提示资源已被删除。
我分析一遍上面的原因,应该是通配URL,导致iis重定向后的URL直接找资源文件,没有通过index.php文件。修改一下上面的链接,让他通过index.php:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="OFF" ignoreCase="true" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/index.php/{R:1}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
但是还会导致新的问题,就是如果访问admin.php后台入口的时候,就会产生:
https://xxx.com/admin.php => https://xxx.com/index.php/admin.php
这种错误的情况,应该要解决这个问题。
那么就需要增加一条伪静态了:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="admin" stopProcessing="true"> <match url="^admin.php(.*)" /> <conditions> <add input="{HTTPS}" pattern="OFF" ignoreCase="true" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> </rule> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="OFF" ignoreCase="true" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/index.php/{R:1}" redirectType="Permanent" /> </rule> <rule name="allow_rules" enabled="true" stopProcessing="true"> <match url="^(.*)$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" /> </rule> </rules> </rewrite> </system.webServer> </configuration>