web.config(IIS)和.htaccess(Apache)配置

admin3年前网站建设24

xml

?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
 
        <httpProtocol>
            <customHeaders>
                <add name="Access-Control-Allow-Origin" value="URL_TO_ALLOW"/>
                <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS"/>
                <add name="Access-Control-Allow-Headers" value="Content-Type"/>
            </customHeaders>
        </httpProtocol>
 
</system.webServer>
</configuration>






forceHTTPS

?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
 
        <rewrite>
            <rules>
 
            <rule name="Force HTTPS" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAll">
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        <add input="{REQUEST_URI}" negate="true" pattern="/ADD_PATTERM_TO_EXCLUDE_FILES_OR_FOLDERS/" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
            </rule>
 
            </rules>
        </rewrite>
 
</system.webServer>
</configuration>






browserCaching

?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Enables browser caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>






customErrorPages

# Sets up custom error pages for 4xx and 5xx errors
ErrorDocument 403 /custom-403
ErrorDocument 404 /custom-404

forceHTTPS

RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't puthere. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* %{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* %{HTTP_HOST}%{REQUEST_URI} [L,R=301]

preventAccessToConfigFiles

# Denies access to all .htaccess files
<Files ~ "^.*\.([Hh][Tt][Aa])">
Order Allow,Deny
Deny from all
Satisfy all
</Files>

urlRewrite

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

好了这篇文章就介绍到这了,需要的朋友可以学习一下。

原文链接:blog.csdn/WuLex

免责声明:本文内容来自用户上传并发布,站点仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。请核实广告和内容真实性,谨慎使用。

相关文章

网站制作策划框架分享

相信任何接触网站业务的人,无论是建站客户,抑或是网站建设供应商,都会在脑海中思考“什么才是好网站”这个问题。 对于这个问题,不同的人因为经历经验不同,会有不一样的答案。行业外的人员,会说“高...

产品网站制作方法步骤

产品网站制作方法步骤,虽然网站对于传统企业来说并不陌生,但很多传统企业对网站还是知之甚少。如果你想推广网站,你首先需要有一个网站。那么,你如何建立网站呢。 1、购买网站域名是网站存在的基础。...

目前主流网站制作页面宽度采用多少合适

众所周知,1000像素是一个门槛,许多新人在设计初期就被灌输了一个概念: 营销网站页面的宽度应该在1000到1004像素之间!随后我们自然而然地在1000像素的城堡里玩耍,不再去触碰外面的世界。诚然,...

IIS怎么禁用匿名用户访问站点

为什么我们要在IIS上禁止匿名访问呢?实际上IIS默认设置中,匿名访问是启用的,这对于一个站点的安全性来说或者网站中有机密信息的就需要对用户进行限制。禁止匿名访问,只有允许特殊的用户才能进行访问,所以...

IIS服务器设置代理实现Node接口转发

前言最近,遇到了一个坑,碰了很多壁,才得以解决所以这里记录一下。也方便大家以后如果遇到的话少踩坑。是这样的,之前搞过Nginx服务器转发Node接口,大体是这样的。比如,我在云服务器上使用Node开发...

SEO新人需警惕的“地雷区”

大学毕业之后没多久,我就从事网站方面的工作,担任网络编辑一职。随着我所在网站的迅速发展,它逐渐开设了各类频道,比如新闻、娱乐、体育等。因为我自己对体育很感兴趣,所以领导便让我负责体育频道。 一个刚工作...