web.config (IIS) and .htaccess (Apache) configuration

web.config (IIS) and .htaccess (Apache) configuration

xml

<?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

<?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="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
			</rule>

			</rules>
		</rewrite>

</system.webServer>
</configuration>

browserCaching

# 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.html
ErrorDocument 404 /custom-404.html

forceHTTPS

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

Well, this is the end of this article. Friends who need it can learn from it.

<<:  Simple use of Vue vee-validate plug-in

>>:  Use and analysis of Mysql Explain command

Recommend

JS Object constructor Object.freeze

Table of contents Overview Example 1) Freeze Obje...

Html sample code for reading and displaying pictures in a local folder

One purpose Select a local folder on the Html pag...

Vue+element+oss realizes front-end fragment upload and breakpoint resume

Pure front-end implementation:切片上傳斷點續傳.斷點續傳needs ...

Docker container log analysis

View container logs First, use docker run -it --r...

Complete steps to use samba to share folders in CentOS 7

Preface Samba is a free software that implements ...

Linux series of commonly used operation and maintenance commands (summary)

Table of contents 1. System monitoring 2. File Op...

How to write transparent CSS for images using filters

How to write transparent CSS for images using filt...

JS implementation of carousel example

This article shares the specific code of JS to im...

Use nexus as a private library to proxy docker to upload and download images

1. Nexus configuration 1. Create a docker proxy U...

mysql splits a row of data into multiple rows based on commas

Table of contents Separation effect Command line ...

New settings for text and fonts in CSS3

Text Shadow text-shadow: horizontal offset vertic...

Win10 64-bit MySQL8.0 download and installation tutorial diagram

How do I download MySQL from the official website...